Ruby on Rails
Thursday, October 4, 2018
Hi John,
-- firstly - I don't know pundit, so this is only general advice.
secondly - we're definitely in the realm of taste and preference here rather than 'ok' and 'not ok'
having said that, my two pence:
the rails style guide says 'Never call the model layer directly from a view'
https://github.com/rubocop-hq/rails-style-guide#no-direct-model-view
I like to think of views as pieces that will do their job of displaying a thing with minimal worrying about the details of the thing. The view shouldn't be worrying about things like user policy
also I wouldn't want authorisation logic in the views just because it is easy to lose track of (and that stuff is important).
my suggestion would be
a) You say you're calling a lot of policy_scope(User)
this sounds like something where a lot of your calls probably need to find a single scoped user at the start. If this is the case, use a before_action
before_action :get_policy_scoped_user, only: [:show, :update, :destroy]
I'd be tempted to have that before_action assigning an @policy_user which I can then pass down to the view.
this keeps the authorisation stuff in the controller, and the view can just display a user's stuff without worrying about what is allowed
so - back to your select. I'd write the view so that it will work when passed any kind of user and doesn't know or care what kind of user it is dealing with.
It just so happens that your controller only passes down a scoped user.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/612fce54-b55f-42d9-91da-f394ec9526af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment