Ruby on Rails
Wednesday, October 24, 2018
Hmmm... That may work...
-- I would always be accessing assessment.data_entries for any lists or views. Reasons and Consequences are basically select criteria for each data entry.
I would never reference reason.data_entries or consequence.data_entries
a has_many :data_entries, :through: :assessment may work though... Let me give that a shot...
Now to figure out how to structure it... :-)
On Wednesday, October 24, 2018 at 7:12:45 AM UTC-4, John Sanderbeck wrote:
On Wednesday, October 24, 2018 at 7:12:45 AM UTC-4, John Sanderbeck wrote:
I'm working on a project that has the following setupI have a table called Assessmentfor each assessment there can be different reasons and consequences defined for that assessmentthen for each assessment the teacher takes multiple data entries over a period of timeeach data entry can choose multiple reasons and consequences from the ones defined in the assessmentSo you have assessmenthas_many :reasonsaccepts_nested_attributes_for :reasonshas_many :consequencesaccepts_nested_attributes_for :consequenceshas_many :data_entriesaccepts_nested_attributes_for :data_entriesThen reasonsbelongs_to :assessmenthas_and_belongs_to_many :data_entriesThen consequencesbelongs_to :assessmenthas_and_belongs_to_many :data_entriesFinally data_entriesbelong to assessmenthas_and_belongs_to_many :reasonshas_and_belongs_to_many :consequencesThere is also a join table for reasons to data_entries, and consequences to data_entriesThe nested table works fine for the reasons, consequences, and the base data_entrieshowever what I cannot get to work is the reasons and consequences chosen in the data_entrieswhat appears to be happening in params is that assessment comes back with data_entries_attributes under ithowever there is also a data_entry param coming back as well, so it is not part of assessment, so the nest is wrong somehow...I have this working in other places however this nest is one level deeper than the others...The way I have the nested form section setup is this...<td><div class="multi-column"><ul><% @assessment.reasons.each do |reason| -%><ul><%= check_box_tag('data_entry[reason_ids][]', reason.id, @assessment.reason_ids. include?(reason.id), :multiple => true) %> <span rel="tooltip" title="<%= reason.assessment_id %>"><%= reason.name %></span></ul><% end %></ul></div></td><td><div class="multi-column"><ul><% @assessment.consequences.each do |consequence| -%><ul><%= check_box_tag('data_entry[consequence_ids][]', consequence.id, @assessment.consequence_ids. include?(consequence.id), :multiple => true) %> <span rel="tooltip" title="<%= consequence.assessment_id %>"><%= consequence.name %></span></ul><% end %></ul></div></td>John
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/749f9533-d198-4f8a-a2a5-98c6c5368452%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment