On Jul 17, 10:27 pm, Barney <bsper...@gmail.com> wrote: > 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-accep...http://railscasts.com/episodes/196-nested-model-form-part-1http://asciicasts.com/episodes/196-nested-model-form-part-1http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/Clas... > > 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
What is the error message? What's the stack trace? > "@Person.people_skills.build" in the "new" method of > people_controller.rb. What's the code in your controller - @Person.people... or @person.people... - is the error message due to a capitalization typo? (wouldn't know without seeing the error msg > > 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.