Sha256: 54c5f640510f38c748a7c5cf686675861482a34c8b171f045413f36163cd5611
Contents?: true
Size: 1016 Bytes
Versions: 3
Compression:
Stored size: 1016 Bytes
Contents
class <%= class_name %> < ActiveRecord::Base # Default validations: exclude_validations = %w{id created_at updated_at} columns.each do |column| unless exclude_validations.include?(column.name) validates_presence_of column.name unless column.null validates_numericality_of column.name, :allow_blank => column.null if column.number? validates_length_of column.name, :maximum => column.limit, :allow_blank => column.null if column.limit end end <%- (attrs = attributes.select{|it|it.name =~ /_id$/}).each_with_index do |a, index| -%> <%- if index == 0 -%> # Only belongs_to can be guessed, uncomment if correct and don't forget to # define has_many on the other side of the relation. <%- end -%> # belongs_to :<%= a.name.sub(/_id$/,'') %><%= ", :polymorphic => true" unless attributes.select{|it|it.name==a.name.sub(/_id$/, '_type')}.empty? %><%= ", :counter_cache => true" unless attributes.select{|it|it.name==a.name.sub(/_id$/, '_count')}.empty? %> <%- end -%> end
Version data entries
3 entries across 3 versions & 1 rubygems