我正在尝试构建一个从Michael Hartl 的 Railstutorial修改的 Rails 应用程序。代码位于GitHub 上。
我正在使用以下嵌套资源:
resources :users do
resources :scaffolds
end
但我收到以下错误:
ActionView::Template::Error (undefined method `scaffolds_path' for #<# <Class:0x007f87848019d0>:0x007f8782651948>):
4:
5: <div class="row">
6: <div class="span6 offset3">
7: <%= form_for(@scaffold) do |f| %>
8: <%= render 'shared/error_messages', object: f.object %>
9: <%= f.text_field :name, placeholder: "Scaffold name" %>
10: <%= f.text_area :description, placeholder: "Description" %>
app/views/scaffolds/new.html.erb:7:in `_app_views_scaffolds_new_html_erb___1119296061714080468_70109999031900'
我很困惑为什么它正在寻找scaffolds_path
而不是user_scaffolds_path
?
在@scaffold
app/controller/scaffolds_controller.rb 中创建:
def new
@scaffold = current_user.scaffolds.build
end
检查@scaffold
由此创建的对象显示:
'#<Scaffold id: nil, name: nil, description: nil, tax_id: nil, user_id: 36, created_at: nil, updated_at: nil>'
转储@scaffold
不显示任何scaffolds_path
或user_scaffolds_path
暗示其他问题的方法的方法?
用户模型has_many :scaffolds
和脚手架模型belongs_to :user
。