0

I have a requirement to have a small system where I have a number of "clubs", and members of this club. A user can be a member of more than one club.

I have the models defined:

club: has_many :club_members has_many :users , through: club_members

user: has_many :club_members has_many :clubs , through: club_members

club_member belongs_to :club belongs_to :user

I have managed to come up with a crude hack (selection list, and storing the member ids as a comma-separated list in the club, but that is so wrong it's making my eyes bleed just looking at the code ;)

What I am trying to achieve is to go to a form, add / remove members, and then when the form is posted , manipulate the models above to permanently save the data accordingly.

So, I actually have 2 questions:

1) Are the models above right ? 2) teaching a man to fish, are there any examples or projects that I can browse / examine that show the relationship management of adding / removing members of a club, both UI and backend ?

many thanks

4

1 に答える 1

0

複雑なフォームに関するレールキャストのこれらのビデオをご覧になることをお勧めします。

http://railscasts.com/episodes?utf8=%E2%9C%93&search=complex+forms

accepts_nested_attributesメソッドを見てください:

http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

于 2012-09-16T12:27:22.323 に答える