
Untitled
By: a guest on
Jun 25th, 2012 | syntax:
None | size: 0.91 KB | hits: 7 | expires: Never
destroy association instead of object
class Category < ActiveRecord::Base
has_many :categorizations
has_many :projects, :through => :categorizations
attr_accessible :name
end
class Categorization < ActiveRecord::Base
belongs_to :project
belongs_to :category
attr_accessible :project_id, :category_id
end
class Project < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations, :uniq => true
accepts_nested_attributes_for :categorizations, :allow_destroy => true
accepts_nested_attributes_for :categories, :allow_destroy => true, :reject_if => lambda { |a| a[:name].blank? }
attr_accessible :name, :description, :content, :icon_id
attr_accessible :categories_attributes
end
<p class="fields">
<%= f.label :name, "Category" %>
<%= f.text_field :name %>
<%= f.hidden_field :_destroy %>
<%= link_to_function "remove", "remove_fields(this)" %>
</p>