ruby - Rails 5, Simple Fields For with Cocoon gem for nested resources -


i trying learn how use namespaced routes.

i have model called proposal , called innovation. associations are:

proposal

has_many :innovations     accepts_nested_attributes_for :innovations, reject_if: :all_blank, allow_destroy: true 

innovation

belongs_to :proposal 

in routes.rb, have:

resources :proposals      resources :innovations 

in proposals controller, have:

def new     @proposal = proposal.new     @proposal.innovations.build      # authorize @proposal   end    def edit     @proposal.innovations_build unless @proposal.innovations    end 

in proposal form, trying nest form fields innovation model.

<%= f.simple_fields_for [@proposal, @innovation] |f| %>         <%= f.error_notification %>           <%= render 'innovations/innovation_fields', f: f %>        <% end %>        <%= link_to_add_association 'add novel aspect', f, :innovations, partial: 'innovations/innovation_fields' %>        </div>   

when try this, error says:

undefined method `model_name' nil:nilclass 

i same error when try:

  <%= f.simple_fields_for [@proposal, @innovations] |f| %> 

can see need in order have proposal form include innovation form fields?

you using nested-attributes, in particular case there no need nested routes. can write

<%= f.simple_fields_for @proposal |f| %> 

this post form, containing innovations, proposalscontroller.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -