For a specific role (group of users) I added the :readonly to every find on the active record
def self.find(*args)
if User.current_user.has_role? 'i_can_only_read'
with_scope({:find => {:readonly => true}}) do
result = super *args
end
end
end
Of course it raises now ActiveRecord::ReadOnlyRecord Exceptions in Controller passed on to the user; not very nice.
Can I catch this type of error in one place? Like in production.rb or in the application.rb? Or can I configure a specific error page for this error?
Yes, simply override rescue_action_in_public like this:
This will execute your action when in “production”, but leave you with an informative stack trace when you are in “development”.
Rails has a number of other rescue_action_* methods that might be more suitable to your problem…take a look at http://api.rubyonrails.org/classes/ActionController/Rescue.html