1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00
heartcombo--simple_form/test/support/models.rb
Carlos Antonio da Silva 27e3e38c05 Adding errors to inputs.
2009-12-08 16:38:03 -02:00

53 lines
1 KiB
Ruby

require 'ostruct'
class User < OpenStruct
def id
1
end
def new_record?
false
end
def column_for_attribute(attribute)
case attribute.to_sym
when :name, :status, :password then :string
when :description then :text
when :age then :integer
when :credit_limit then :decimal
when :active then :boolean
when :born_at then :date
when :delivery_time then :time
when :created_at then :datetime
when :updated_at then :timestamp
end
end
def human_attribute_name(attribute)
nil
end
def errors
{}
end
end
class SuperUser < User
def human_attribute_name(attribute)
case attribute
when 'name' then 'Super User Name!'
else super
end
end
def errors
@errors ||= {
:name => "can't be blank",
:description => "must be longer than 15 characters",
:age => ["is not a number", "must be greater than 18"],
:credit_limit => ["must be present", "must be greater than 0"]
}
end
end