Set has_many: through the game and use it in real form

class Allowedevent < ActiveRecord::Base
    :belongs_to :room
    :belongs_to :event
end

class Room < ActiveRecord::Base
    :has_many :allowedevents
    :has_many :events => :through => allowedevents
end

class Event< ActiveRecord::Base
    :has_many :allowedevents
    :has_many :rooms=> :through => allowedevents
end

I find it difficult to put the above relationships into a form or play with them in the console.

Questions:

  • Now let's say that I save the room, do I need to explicitly add identifiers to the table allowedevents? I must do it?

    room = Room.new; room.title = "test"; room.allowedevents = "" ...?

    as you can see from above, I am losing information on how to save the actual record.

  • Basically I want to ask how to save a room in a database that has a lot allowedeventsusing the above relationships. Do I need to go through user input and save each in allowedevents? is there a better way?

  • railscasts, railscasts, , ?

+3
1

, . , .

. accepts_nested_attributes_for, , , .

accepts_nested_attributes_for , "_delete" , . , javascript "_delete" , - , javascript, .

accepts_nested_attributes_for , , , accepts_nested_attributes_for .

, RailsCast, , :

http://railscasts.com/episodes/73-complex-forms-part-1

- accepts_nested_attributes_for has_many: , .

+2

All Articles