In Rails 4:
class Anything < ActiveRecord::Base before_create :only_one_row private def only_one_row false if Anything.count > 0 end end
Silent mistakes then
class Anything < ActiveRecord::Base before_create :only_one_row private def only_one_row raise "You can create only one row of this table" if Anything.count > 0 end end
source share