I know that you can only render / redirect_to once in a controller
action, but I was wondering if there’s a property I can check to see if
a render / redirect_to has been called. For example, I have a method I
call to check access to a page, but I can’t do it in a filter because
the page needs to be loaded first in order to check the permissions.
(I’m writing a CMS and the pages are loaded dynamically based on the URL
passed in)
Here’s a simplified version of my code:
In my PagesController:
def index
See if page is member’s only
require_member if @page.private?
if not, redirect to the proper page
redirect_to pages_url(@page) and return
end
In my ApplicationController:
def require_member
unless current_member
store_location
redirect_to login_url and return
end
end
The issue is that because require_member is in my application controller
(so it can be used by other controllers) the “and return” is returning
execution back to the calling method instead of actually ending
execution.
Is there a way to check to see if require_member initiated a redirect
without setting a session / global flag?