I’m integrating some basic authorization stuff. When a user hits
/countries/some_unknown_action, then Rails displays a “Unknown action”
message (in development mode). When an unauthorized user hits
/countries/action_that_needs_authorization, then I’d like Rails to
behave exactly the same way (because some error like “you don’t have
permission to…” would encourage hackers to re-attempt the action).
But I guess that’s not really the best way, because it’s hard-coded and
doesn’t rely on Rails’ own mechanism to display the 404 page. So I tried
it using
raise ActionController::UnknownAction
But it seems that this Exception is only used by the functional tests.
So what should I do to rely on Rails’ own mechanism to display the 404
page?
Wouldn’t anyone seeing that error just become confused as to why a
development-mode error message was being shown during a production
environment, though? This would encourage me to dig deeper than just a
‘get out of my stuff’ message.
I already tried it with
But it seems that this Exception is only used by the functional tests.
So what should I do to rely on Rails’ own mechanism to display the 404
page?
Wouldn’t anyone seeing that error just become confused as to why a
development-mode error message was being shown during a production
environment, though? This would encourage me to dig deeper than just a
‘get out of my stuff’ message.
Well, maybe I confused some stuff in my post. In fact I just want to
imitate the same behavior that Rails shows when an unknown action is
called, independent of whether I’m in development or in production mode:
When in development mode, do what Rails would do
When in production mode, do what Rails would do
I then only added the useful exception (in my 2nd post) of displaying
some more info for developers so they can distinguish between really not
existing actions and now allowed actions.