Sha256: 05723edcd3774fa659747af19cb4a7d52046909dd7e9466a95dc9b74e3487671
Contents?: true
Size: 1.82 KB
Versions: 6
Compression:
Stored size: 1.82 KB
Contents
module Applicat module Mvc module Model module Resource module Base def self.included(base) base.class_eval do cattr_reader :per_page @@per_page = 20 attr_accessor :current_user if self.table_exists? columns.map(&:name).select{|c| c.match('_id')}.each do |column| association = column.split('_id').first.classify define_method "#{association.underscore}_name" do self.send("#{association.underscore}").try(:name) end accessible_attributes << "#{association.underscore}_name" define_method "#{association.underscore}_name=" do |name| return if name.blank? association_type = association if self.class.columns.map(&:name).include?("#{association.underscore}_type") association_type = self.send("#{association.underscore}_type") end begin association_type = association_type.constantize rescue association_type = self.class.reflections[column.split('_id').first.to_sym].options[:class_name].constantize end self.send("#{association.underscore}=", association_type.find_or_initialize_by_name(name)) end end end def to_s self.name rescue self.class.name.humanize end end end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems