While redesigning an existing application, I’ve stumbled on a problem.
A number of links on the site requires that the user logs in. This is
currently solved by the simple (example)
<%=link_to ‘Upload image’, :controller => ‘image’, :action => ‘new’ %>
and in the ImageController I place a
before_filter :login_required, :only => :new
(login_required checks the session userdata, and redirects to a
login-page if necessary)
I want to change it at bit, so that when the user clicks the link - and
a login is actually required - a modalbox popup containing a login form
pops up on the same page as where the user clicked on the link
My issue is how to detect if the controller/action requires a login?
I am working on the concept to do something like this in the view
<%=protected_link_to ‘Upload image’, :controller => ‘image’, :action =>
‘new’ %>
and in the helper:
def protected_link_to(caption, options = {}, html_options = {})
if
var url = url_for(options)
return link_to_function caption, “show_login_popup(…blabla…,
{continue_url: url});”
end
return link_to caption, options, html_options
end
Question is: How do I implement the if
Thanks
- Carsten