Sha256: 968e3ec0194da88623dcb0dbb51cbe5fe3ea4022a911b7e3d3e8c1d1c5877c2a
Contents?: true
Size: 1.07 KB
Versions: 9
Compression:
Stored size: 1.07 KB
Contents
class <%= class_name %> < ActiveRecord::Base attr_accessible <%= attributes.map { |a| ":#{a.name}" }.join(", ") %> <%- first_attribute = attributes.first -%> def self.page(search, page) paginate :per_page => 10, :page => page, :order => '<%= first_attribute.name %>', :conditions => ["<%= first_attribute.name %> LIKE ?", "%#{search}%"] end has_one :menu_item, :as => :linkable, :dependent => :destroy after_create :create_menu_item after_update :update_menu_item def update_menu_item @menu_item = self.menu_item if @menu_item == nil self.create_menu_item else @menu_item.update_attributes( :title => self.<%= first_attribute.name %>, :url => "/view-<%= singular_name %>/#{self.<%= first_attribute.name %>}", :active => self.<%= first_attribute.name %> ) end end def create_menu_item @menu_item = self.build_menu_item( :title => self.<%= first_attribute.name %>, :url => "/view-<%= singular_name %>/#{<%= first_attribute.name %>}", :active => self.<%= first_attribute.name %> ) @menu_item.save end end
Version data entries
9 entries across 9 versions & 1 rubygems