简体   繁体   中英

How do allow to use a scope only to admin users with a certain value in Rails 4 model?

In my recent Rails project I have a scope in a model. This scope has two possible values: true or false.

scope :ultima, -> ultima { where(:ultima => ultima ) 

I´m using has_scope gem to allow using this scope in controller so I can do calls like this:

http://localhost:3000/model?ultima=true

or

http://localhost:3000/model?ultima=false

In this project, I have normal users and admin users who have special access to some parts of the application.

How do you allow to use this scope with value 'false' to admin users; but when value is 'true' is allowed to everyone?

I generally use Rolify and Pundit to accomplish this. Rolify sets :admin on the model. And pundit has a scope where i check if user is :admin.

You can also do this through a namespace and have a separate admin controller that you lock this down with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM