Replies: 1 comment 3 replies
-
Agree.
What do you mean by different errors? How to differentiate between
Yeah, that would be great. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey, I recently came across this gem and I would want to integrate it in an application I'm currently working on, however, I am struggling to port some of the logic that's present in my controllers.
Say I've got a controller named
ObjectsController
, this controller locates/fetches an object in a before_action callback:before_action :set_object, except: [:index, :destroy]
However, this
set_object
method calls a method that's included from a concern module, theset_object
method looks like that:The concern is really simple and it's worth mentioning that more than one controller include it:
The bit I'm struggling with the most is error handling, I can see that we can rescue
ActionPolicy::Unauthorized
and handle exceptions accordingly but I'm more or less rewriting the same logic in a similar concern, I just don't understand how to handle different errors that require some action, in my specific case above I need to redirect to a path. I don't want to return back to the policy on errors and call a method in there as it really breaks the rule for separation of concerns, i.e. policies shouldn't know about controllers, any help/directions appreciated! I can post what I came up with but in my opinion it's far from ideal and introduces a lot more complexity than just that simple concern above. Thanks!Beta Was this translation helpful? Give feedback.
All reactions