Hello,
     An earlier post where I asked how to put mulitple tables's input
on one screen was answered with "accepts_nested_attributes_for" and
that seems to be what I need, but nothing appears on the screen for
the nested section.  I've been using ideas from:

http://masonoise.wordpress.com/2010/07/23/rails-and-forms-using-accepts_nested_attributes_for/
http://railscasts.com/episodes/196-nested-model-form-part-1
http://asciicasts.com/episodes/196-nested-model-form-part-1
http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for

The following are my classes and a little code from the
"_form.html.erb" that I'm trying to make work:

class Person < ActiveRecord::Base
        default_scope :order => 'last_name'
        has_many :people_skills

        accepts_nested_attributes_for :people_skills, :update_only =>
true, :allow_destroy => true
end

class PeopleSkill < ActiveRecord::Base
        belongs_to :person
end

Also, there is a field in the people_skills table that is person_id,
which I remember reading in the "Agile.." book creates an FK there.

<%= form_for(@person) do |f| %>
  <% if @person.errors.any? %>
    # ... usual code concerning errors
  <% end %>

  <%= f.fields_for :people_skills do |builder| %>
      <%= builder.label :skill, "Skill" %><br />
      <%= builder.text_field :skill %>
    </p>
    <p>
      <%= builder.label :competency, "Competency" %><br />
      <%= builder.text_field :competency %>
    </p>
  <% end %>

  <table>
    <tr>
      <td>
        <div class="field">
          <%= f.label :first_name %><br />
          <%= f.text_field :first_name %>
        </div>
      </td>
      <td>
AND THEN MANY OTHER ROWS AND FIELDS OF THIS TABLE.

The table data for the class "Person" shows up fine, but anything with
the "f.fields_for..." is invisible (but doesn't cause a syntax
error).  What DOES cause an error is to put
"@Person.people_skills.build" in the "new" method of
people_controller.rb.

So, I'm looking for a way to have one screen which creates entries in
2 tables, linked by the PK-FK.  What am I doing wrong or forgetting to
do?
     Thanks,
          Barney

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to