class <%= level.name.camelize %> < <%= level.subclass? ? level.superclass.name.camelize : 'ActiveRecord::Base' %> strip_attributes! <%- if level.sortable? -%> acts_as_list<%= if level.polymorphic? " :scope => [:#{level.polymorphic_name}_type, :#{level.polymorphic_name}_id]" elsif level.nested? " :scope => :#{level.parent_associations.find(&:nest?).parent_name}" end %> <%- end -%> # ATTRIBUTES <%- if level.attr_accessors? -%> <%= level.attr_accessors %> <%- end -%> <%- if level.attr_accessibles? -%> <%= level.attr_accessibles %> <%- end -%> <%- if level.belongs_to_one? -%> attr_accessor :nested <%- end -%> # FILTERS # ASSOCIATIONS <%- if level.parent_associations.find(&:non_polymorphic?) -%> <%- level.parent_associations.select(&:non_polymorphic?).each do |association| -%> belongs_to :<%= association.parent_name %> <%- end -%> <%- end -%> <%- if level.parent_associations.find(&:polymorphic?) -%> <%- level.parent_associations.select(&:polymorphic?).each do |association| -%> belongs_to :<%= association.parent_name %>, :polymorphic => true <%- end -%> <%- end -%> <%- if level.child_associations.find(&:non_polymorphic_one_to_many?) -%> <%- level.child_associations.select(&:non_polymorphic_one_to_many?).map(&:child).each do |child| -%> has_many :<%= child.name.pluralize %>, :dependent => :destroy <%- if child.join? -%> has_many :<%= child.other_parent_name(level.name).pluralize %>, :through => :<%= child.name.pluralize %> <%- end -%> <%- end -%> <%- end -%> <%- if level.child_associations.find(&:non_polymorphic_one_to_one?) -%> <%- level.child_associations.select(&:non_polymorphic_one_to_one?).each do |association| -%> has_one :<%= association.child_name %>, :dependent => :destroy <%- end -%> <%- end -%> <%- if level.child_associations.find(&:polymorphic_one_to_many?) -%> <%- level.child_associations.select(&:polymorphic_one_to_many?).each do |association| -%> has_many :<%= association.child_name.pluralize %>, :as => :<%= association.polymorphic_name %>, :dependent => :destroy <%- end -%> <%- end -%> <%- if level.child_associations.find(&:polymorphic_one_to_one?) -%> <%- level.child_associations.select(&:polymorphic_one_to_one?).each do |association| -%> has_one :<%= association.child_name %>, :as => :<%= association.polymorphic_name %>, :dependent => :destroy <%- end -%> <%- end -%> # NESTING <%- if level.child_associations.find(&:one_to_one?) %> <%- level.child_associations.select(&:one_to_one?).each do |association| -%> accepts_nested_attributes_for :<%= association.child_name %> <%- end -%> <%- end -%> # ATTACHMENTS <%- if level.attachments? -%> <%= level.attached_files %> <%- end -%> # VALIDATIONS <%- if !level.subclass? && level.validations? -%> <%= level.validations.join("\n ") %> <%- end -%> # SCOPES scope :collection # METHODS def to_s <%= level.to_s_string || (level.join? && level.nested? && level.parent_associations.find(&:nest?).parent_name) || '"##{id}"' %> end end