Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with Rails 3 has_many :through association and views/forms
    primarykey
    data
    text
    <p>I have previously used has_and_belongs_to_many associations in my older Rails apps but am moving to using has_many, :through for new and current apps. However, I believe I am missing something central to the has_many, :through association in Rails 3. </p> <p>Currently, I am building an app for our town's volunteer fire department. When we have a meeting, we want to check off whether or not a fire fighter is present, excused, or absent. </p> <p>My models:</p> <pre><code>#FireFighter Model class FireFighter &lt; ActiveRecord::Base has_many :attendance_meetings has_many :meetings, :through =&gt; :attendance_meetings accepts_nested_attributes_for :meeting #Meeting Model class Meeting &lt; ActiveRecord::Base has_many :attendance_meetings has_many :fire_fighters, :through =&gt; :attendance_meetings accepts_nested_attributes_for :fire_fighter #AttendanceMeeting Model class AttendanceMeeting &lt; ActiveRecord::Base attr_accessor :status # this is the added property on the join model that we need populated belongs_to :fire_fighter belongs_to :meeting </code></pre> <p>The problem I'm having is how to set this up in the view. Currently, I have:</p> <pre><code>= hidden_field_tag "meeting[fire_fighter_ids][]" -@meeting.fire_fighters.each do |fire_fighter| = fire_fighter.fire_fighter_name %span.radio_btn= radio_button_tag :fire_figher_ids, fire_fighter.id, "present" present %span.radio_btn= radio_button_tag :fire_figher_ids, fire_fighter.id, "excused" excused %span.radio_btn= radio_button_tag :fire_figher_ids, fire_fighter.id, "absent" absent %br </code></pre> <p>This will spit out each fire fighter and three radio buttons for each fire fighter (with options for present, excused, or absent). However, the name of the resulting radio buttons are all the same, so you can only pick one for all fire fighters. </p> <p>As I noted above, I feel certain I am missing something basic but I am stumped. I've read through tons of SO questions and The Rails 3 Way book's sections on ActiveRecord. Any suggestions or directions would be most appreciated. Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload