This is "thin controllers" gone too far -- the model shouldn't have to figure out where it's being updated from and what to allow.
This is "thin controllers" gone too far -- the model shouldn't have to figure out where it's being updated from and what to allow.
attr_accessible :user_id, :on => :admin
And in controllers (or anywhere, really): @something.update_attributes(params[:something], :as => :admin)
It's naive and it's not exactly an ACL or anything but it's a way to indicate the context at a basic level.Sadly, people seem to be running around like headless chickens trying to scotch tape trash bags over a broken window instead of learning how to replace the glass.
1) The model could be used everywhere so it may be best to negate the issue by locking down the attributes at one source.
2) As you pointed out, the model is in different contexts depending on the privilege of the current user session. It's almost as if I want a thin layer between my model and controller that takes into account session info and informs the model about what can and can't be done.
What I don't know is if RoR allows for this sort of modeling. I have no experience with the framework. It might want something that is similar to getters/setters in Java. If this is the case, such a modeling is problem not going to work since the multiple params will break the spec.
It's really an authorisation issue as to who/what can update which parts of a model - generally this is handled in the controller.