Reputation: 27
In the application I'm creating, I have a model:
class Stat < ActiveRecord::Base
end
I create 6 unique instances of Stat
in the file db/seed.rb
and I don't want there to be any way to create more instances or destroy the ones I've created. I don't want the instances that do exist to be read_only, modifying some of the attributes is fine and I know how to prevent others from changing. But I can't find any way of locking down the model itself.
I'm fairly new to Ruby on Rails development. Is this possible?
Upvotes: 0
Views: 172
Reputation: 2055
Use the before_create/destroy
filters.
class Stat < ActiveRecord::Base
before_create -> (model) { raise SomeError }
before_destroy -> (model) { raise SomeError }
end
Upvotes: 2