Friday, 15 July 2011

ruby on rails - nested forms and cocoon. undefined method `label' for nil:NilClass -



ruby on rails - nested forms and cocoon. undefined method `label' for nil:NilClass -

hi all. when open /courses/new (or /courses/some_id/edit), browser returns error:

showing /app/views/dashboard/courses/_price.html.erb line #1 raised: undefined method `label' nil:nilclass

here codes, _form.html.erb:

<%= simple_form_for [:dashboard, @course], html: { multipart: true } |f| %> ////// <%= f.fields_for :prices |p|%> <%= render 'price', :f => 'prices' %> <% end %> <%= link_to_add_association 'add', f, :prices %> ////////

_price.html.erb:

<%= p.label :price %> <%= p.text_field :price %> <%= p.label :desc %> <%= p.text_field :description %> <%= link_to_remove_association "remove", f %>

models:

class cost < activerecord::base belongs_to :course end class course of study < activerecord::base has_many :prices accepts_nested_attributes_for :prices, :reject_if => :all_blank, :allow_destroy => true end

how resolve error? , why has arisen?

you using simple_form_for,so guess line

<%= f.fields_for :prices |p|%>

should

<%= f.simple_fields_for :prices |p|%>

have @ git more info.

ruby-on-rails ruby ruby-on-rails-4 nested-forms cocoon-gem

No comments:

Post a Comment