David Lyod
David Lyod

Reputation: 1438

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 unable 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.

Upvotes: 1

Views: 2764

Answers (1)

Related Questions