Has_many :through and form parameters

The standard setup:

class Task:
has_many :studies, :class_name => “Study”
has_many :datasets, :through => “studies”

class Dataset:
has_many :studies
has_many :tasks, :through => ‘studies’

class Study:
belongs_to :task
belongs_to :dataset

Now, if I have an edit view for my Task, is it possible to set up the
form so that in the create (or update) action “@task = params[:task]”
will set up @task so that, for instance @task.studies would return all
associated studies, @task.studies.each {|s| p s.dataset} would print
all the datasets, etc: in other words, all the code that has_many
:through buys you would just work.

OR, do I have to pull out the params[:task][:studies], call Study.new
for each of them, and then put the @task variable back together again?

I hope this makes sense. I’ve found some similar queries on the list
but no real satisfactory answers.


James H.
Web application developer
Vancouver, BC

“Developing a coherent political analysis is in many respects
contingent upon an ability to connect one context to another, a
process not dissimilar to playing the kid’s game of dot-to-dot.”

  • Ward Churchill, from ‘“A Government of Laws”?’

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs