The codes are as follows:
class Seat < ActiveRecord::Base
attr_accessible :baggage, :flight_id, :name
def validate(record)
errors.add_to_base("You have too much baggage")
end
end
I expected it throws error whenever a new record is wriiten into the database.
However, nothing happened when new record wriiten into seats database by @seat.save
Does anyone have ideas about this?
validate(record)looks weird. You should tryAlso note that you need to call
@seat.save!(instead of@seat.save) in order to get the exception.@seat.savewill return true or false only … but that’s usually what you want, so consider if you really want to raise an exception.