I have searched high and low without finding a "good" resource (sample code) for has_many through relationships. Do you have any recommendations? Thanks, Sunny --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sunny Beach wrote:> I have searched high and low without finding a "good" resource (sample > code) > for has_many through relationships. > > Do you have any recommendations? > > Thanks, > SunnyMaybe this might help? http://railscasts.com/episodes/3 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This is an old design, but I have Tests, Processes, and data to manage for each combination (I think I''ve seen this called "HABTM with attributes"). A Test can test many processes, a process can be used in many tests. For each Test-Process, there can be success/failure, and notes. class Test < ActiveRecord::Base # id # test_name # test_protocol has_many :proctests has_many :aprocesses, :through => :proctests end class Proctest < ActiveRecord::Base # id # passfail # notes # test_id # aprocess_id belongs_to :AProcess belongs_to :Test end class Aprocess < ActiveRecord::Base # id # proc_name # process_notes has_many :proctests has_many :tests, :through => :proctests end Essentially proctest is a join table with data of its own. From the Test show view, I can list all the processes it tests: <% if @test.aprocesses <%= render_partial ''test_process_list'', nil, ''test_id'' => @test.id , ''testname'' => @test.test_name, ''processlist'' => @test.aprocesses %> in that partial, there''s code like: <% for aprocess in processlist %> blah blah blah <% end %> and vice-versa: From the Aprocess show view, I can list all the Tests which test it: <%= render_partial ''aprocess_test_list'', nil, ''aprocess_id'' => @aprocess.id, ''process'' => @aprocess.proc_name, ''testlist'' => @aprocess.tests %> in that partial, there''s code like: <% for test in testlist %> blah blah blah <% end %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I think I figured out the basics. For those looking for the info in the future there are a couple links below. This link was very helpful creating the model code: http://paulbarry.com/articles/2007/10/24/has_many-through-checkboxes This was helpful with the simple view: http://www.railsforum.com/viewtopic.php?id=15844 This was also somewhat helpful for creating the check boxes: http://railscasts.com/episodes/17 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---