ruby on rails - Using :attr_accessible with role-based authorization -


In my online store, users are allowed to change some qualities of their order (e.g., their billing address), but No other (e.g., Origination IP address). Administrators on the other hand are allowed to modify the all order properties.

Given this, how can I properly use : attr_accessible to safeguard the order model? Or I have to use it to mark all the attributes which can prevent administrators from modifying and consuming them by using Order.update_attributes (params [: order]) . What common users can access in those control actions?

If you want to update specific features in a model, then you can do something like this:

  class command & lt; ActiveRecord :: Base Def update_attributes_as_user (value, user) values.each do | Attribute, value | # If the user has the permission of @ order.send ("# {attribute} =", value), then update the attribute if user.can_modify? (Specialty) save the end of the end end  

Then you can change your order.update_editibles (parameters [: order]) to order. Update_data_user (parameter [: order], current_user) and you agree User # Can_modify? The method to return right in the right cases, it should work.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -