Unknown attribute: version (nested forms)

I try to update a nested model (version) and get this error. any tips
would be great!

my models: location has_many :versions


<% form_for location do |location_form| %>

  • <%= location_form.label location.section %>

  • <%= location_form.label location.sub_section %>

  • <%= location_form.label location.place_holder %>

<div class="content-area">
   <% location.versions.each do |version| %>
      <div class="content" >
        <% location_form.fields_for version do |version_form| %>
          <%= version_form.label version.environment %>
          <%= version_form.text_area :content %>
        <% end %>
  <% end %>
  <%= submit_tag %>

<% end %>


def update
@location = Location.find(params[:id])
@location.update_attributes(params[:location]) #error: unknown
attribute: version
redirect_to( locations_path )

the params

{“location”=>{“version”=>{“content”=>“hello human. glass robot want
you to join Glass”}}, “commit”=>“Save changes”,

Where’s the error message?

ActiveRecord::UnknownAttributeError in LocationsController#update

unknown attribute: version

RAILS_ROOT: /home/oren/misc/projects/borderstylo/content

active_record/base.rb:2746:in attributes=' /opt/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/ active_record/base.rb:2742:ineach’
active_record/base.rb:2742:in attributes=' /opt/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/ active_record/base.rb:2628:inupdate_attributes’
locations_controller.rb:29:in `update’

Hi Oren,

Try this “accepts_nested_attributes_for :versions” in the location.rb


I already have this:

has_many :versions, :dependent => :destroy
accepts_nested_attributes_for :versions

This is how I did my nested forms (actually I have 3 forms nested):

<% form_for [@resource, @validity] do |f| %>
<% f.fields_for :timesheets do |t| %>
<% t.fields_for :values do |v| %>
R$ <%= v.text_field :value, :maxlength=>10 %>
<% end %>
<% end %>
<%= f.submit “Save” %>
<% end %>

resource has_many validities
validity has_many timesheets
timesheet has_many values

I use version and not :vorsion here: (since i believe i need to
provide an object)
location_form.fields_for version do |version_form|

could it be related to the issue?

It works now. I had 2 loops and had to remove the external one:
<% location.versions.each do |version| %>

fields_for already create a loop on the children, so there is no need
for another loop.