【发布时间】:2016-11-06 01:14:05
【问题描述】:
我正在尝试学习如何使用命名空间路由。
我有一个模型叫提案,另一个模型叫创新。这些关联是:
建议
has_many :innovations
accepts_nested_attributes_for :innovations, reject_if: :all_blank, allow_destroy: true
创新
belongs_to :proposal
在我的 routes.rb 中,我有:
resources :proposals do
resources :innovations
在我的提案控制器中,我有:
def new
@proposal = Proposal.new
@proposal.innovations.build
# authorize @proposal
end
def edit
@proposal.innovations_build unless @proposal.innovations
end
在我的提案表单中,我尝试为创新模型嵌套表单字段。
<%= f.simple_fields_for [@proposal, @innovation] do |f| %>
<%= f.error_notification %>
<%= render 'innovations/innovation_fields', f: f %>
<% end %>
<%= link_to_add_association 'Add another novel aspect', f, :innovations, partial: 'innovations/innovation_fields' %>
</div>
当我尝试这个时,我收到一条错误消息:
undefined method `model_name' for nil:NilClass
我尝试时遇到同样的错误:
<%= f.simple_fields_for [@proposal, @innovations] do |f| %>
谁能看到我需要做什么才能让提案表单包含创新表单字段?
【问题讨论】:
标签: ruby-on-rails ruby simple-form nested-attributes cocoon-gem