has_many through checkboxes
Given the following models
class Feed < ActiveRecord::Base
has_many :alerts , :dependent => :destroy
has_many :users , :through => :alerts
end
class Alert < ActiveRecord::Base
belongs_to :user
belongs_to :feed
has_and_belongs_to_many :alerttypes
end
class Alerttype < ActiveRecord::Base
has_and_belongs_to_many :alerts
end
I can create a form to list the Alerttypes when adding a new Feed and this submits correctly. I am however un开发者_JAVA百科able to update these Alerttypes successfully. I cannot seem to find the correct method for defining the checkbox naming
<%= check_box_tag "UNKNOWN", type.id , @alerts[0].alerttypes.include?(type)%>
The checking of the Alerttypes being 'checked' works but any changes in those Alerttypes when editing does not update and they stay as when first created.
Have you seen this: http://millarian.com/programming/ruby-on-rails/quick-tip-has_many-through-checkboxes/ ?
精彩评论