如何找到@object然后复制@object?

下面的代码预先填充了一个新的_form ,但是一旦用户保存表单,它将更新旧的Inspiration而不是创建新的Inspiration 。 调节器 def new if params[:inspiration_id] @inspiration = Inspiration.find(params[:inspiration_id]) @inspiration = current_user.inspirations.build # Is there a way to find and then build? else @inspiration = current_user.inspirations.build end end 路径 new_inspiration_path(inspiration_id: inspiration.id) 我们怎样才能将@inspiration首先用于Inspiration.find(params[:inspiration_id])然后再使用current_user.inspirations.build ?

Rails:ActionView :: Template :: Error(NilClass的未定义方法`model_name’:Class):

可能重复: MetaSearch“未定义的方法`model_name’用于NilClass:Class”用于全局条形搜索 当我尝试访问用户的个人资料或个人post(/ posts / 1)时,这是我使用更新的代码时出现的错误。 奇怪的是它试图访问不同的部分,因为它是一个没有任何喜欢的新用户。 我得到的代码完全如我在以下用户使用的教程中所示。 对于跟随用户的用户来说,它可以正常工作,但我已经设置好了尝试与喜欢post的用户一起工作。 ActionView::Template::Error (undefined method `model_name’ for NilClass:Class): 1: { :method => :delete }, 3: :remote => true) do |f| %> 4: app/views/users/_unlike.html.erb:1:in `_app_views_users__unlike_html_erb___769256097635878617_2160255900__1293121959744503098′ app/views/users/_like_form.html.erb:6:in `_app_views_users__like_form_html_erb___3308190581058867471_2162903180_52867338942162503′ app/views/posts/show.html.erb:7:in `_app_views_posts_show_html_erb___3188789470217885182_2183453320__3624460432667345580′ 这里有几乎所有东西的馅饼,如果我错过了什么,请告诉我。 我真的很感激能够让这个工作变得有意义。 http://pastie.org/1824955

Factory Girl + Rspec给出以下错误:ActionView :: Template :: Error :(对象id)不是id值

我定义了一个课程>>级别>>和工厂女孩的步骤。 Step属于level和level属于course(其中每个都有另一种has_many关系)。 这是错误(我甚至不知道从哪里开始): Failure/Error: before { visit course_level_step_path(course.id, level.id, step.id)} ActionView::Template::Error: 0x003fe5daf528a0 is not id value 这是我要求的路线: course_level_step GET /courses/:course_id/levels/:level_id/steps/:id(.:format) steps#show 在这里我的rspec: describe “attempting a step” do let(:course) { FactoryGirl.create(:course)} let(:level) { FactoryGirl.create(:level)} let(:step) { FactoryGirl.create(:step)} before { sign_in user} describe “taking a course” do before { visit course_level_step_path(course.id, level.id, step.id)} <<< here is the […]

Rails按关联数据排序

是否可以按教师的名字订购school.classrooms的结果? 我想直接在关联中执行此操作,而不是单独调用。 class School < ActiveRecord::Base has_many :classrooms end class Classroom < ActiveRecord::Base belongs_to :school belongs_to :teacher end class Teacher < ActiveRecord::Base has_one :classroom end

Rails上的角度模板

我正在使用angular-rails-templates gem。 我的/app/assets/javascripts有一个名为templates的文件夹,我将它包含在application.js : //= require_tree ./templates 在模板内部有一个带有 hello world 的test.html文件。 出于某种原因,当我在控制台中注销$templateCache.info() (使用app.run )时,我找不到test.html : 对象{id:“templates”,大小:0}

Rails – 如何将一些信息从一个表单发送到其他控制器

首先,我想描述一下我将要做的事情。 因此,我的应用程序是一组任务(例如,练习依赖于编写计算机程序),用户可以通过表单发送解决方案,服务器将编译它并返回进程结果。 我的问题是我有模型Solution ,如下所示: Solution(id: integer, exercise_id: integer, code: string, user_id: integer, created_at: datetime, updated_at: datetime, language_id: integer) 和exercise_id, user_id, language_id是外键和postgresql返回错误,它不能是空值…我用来发送此信息的表单如下所示: Send solution { role: “form” } do |f| %> “btn btn-default” %> 坦率地说,我不知道如何包含更多信息,如user.id或exercise.id。 参数看起来像: @_params {“utf8″=>”✓”, “authenticity_token”=>”abwhTn3KrVneli0pCVccoWHyzlI7cRTFK5Wo7DdYRK+lL4GwZ8jUPqdzn8ZznCHsWTkfDAFS2RP6gTkWuk33iw==”, “solution”=>{“code”=>”ds”, “language_id”=>”C++”}, “commit”=>”Wyślij”, “controller”=>”solutions”, “action”=>”create”, “exercise_id”=>”1”} SolutionController class SolutionsController < ApplicationController def index @solutions = Solution.last(20) end […]

在rails’link_to块上的ruby中等效于“data-hover:”

我有以下HTML Seraglio 如何将其转换为RoR?

与ror托管错误

我在aws ec2中托管了一个ror应用程序。 开发环境工作正常,但当我开始生产模式时,它说 – “我们很抱歉,但出了点问题。我们已经收到有关此问题的通知,我们很快就会对其进行审核。” 我chechked production.log production.log [2015-07-02T16:37:21.257777 #12834] INFO — : Migrating to (20150608154559) 像这样,所有表名都显示为具有迁移的消息。 这是一个错误吗? 怎么解决这个?

pg gem Trace / BPT陷阱:MAC OS X上的5个错误

我最近将我的雪豹升级为狮子,并在我的一个应用程序中升级 => Booting WEBrick => Rails 3.0.4 application starting in development on http://0.0.0.0:4000 => Call with -d to detach => Ctrl-C to shutdown server [2011-08-16 17:47:27] INFO WEBrick 1.3.1 [2011-08-16 17:47:27] INFO ruby 1.9.2 (2011-07-09) [x86_64-darwin11.0.0] [2011-08-16 17:47:27] INFO WEBrick::HTTPServer#start: pid=3460 port=4000 Trace/BPT trap: 5 应用程序退出并且没有其他输出,它确实以sqlite3作为db gem运行。 我评论了所有其他gem,但是这个仍然得到了错误。 我看到这个错误不是在应用程序加载时,而是在它尝试回答第一个请求时。 任何人都知道另一个gem连接到postgresql或任何解决方法? 编辑:好的,这里有一些澄清。 我在雪豹上开始了这个项目,它运行得很好,我安装了rvm,pg gem,webrick和ruby 1.9.2-p180,我升级到狮子并继续从事其他项目,当时间来更新这个项目时,我得到了Trace/BPT trap: […]

如何在rails 3.1中为作用域/嵌套资源创建named_route_path?

这是我的路线: scope “:username” do resources :feedbacks end 当我做rake routes ,我明白了: feedbacks GET /:username/feedbacks(.:format) {:action=>”index”, :controller=>”feedbacks”} POST /:username/feedbacks(.:format) {:action=>”create”, :controller=>”feedbacks”} new_feedback GET /:username/feedbacks/new(.:format) {:action=>”new”, :controller=>”feedbacks”} edit_feedback GET /:username/feedbacks/:id/edit(.:format) {:action=>”edit”, :controller=>”feedbacks”} feedback GET /:username/feedbacks/:id(.:format) {:action=>”show”, :controller=>”feedbacks”} PUT /:username/feedbacks/:id(.:format) {:action=>”update”, :controller=>”feedbacks”} DELETE /:username/feedbacks/:id(.:format) {:action=>”destroy”, :controller=>”feedbacks”} 但是当我做feedbacks_url或feedbacks_path时,我得到一个像这样的路由错误: No route matches {:controller=>”feedbacks”, :format=>nil} 从日志文件: Rendered users/show.html.erb within layouts/application (18.3ms) Completed […]