I have an ajax voting button: If a user clicks on a \"thumbs up\" image, but is not logged in, then they should see a dialog box that asks them to login first.
To do thi
I do the following with Authlogic on Rails 3, perhaps you could use it or do something similar:
class ApplicationController < ActionController::Base
after_filter :store_location
private
def store_location
session[:return_to] = request.fullpath
end
def clear_stored_location
session[:return_to] = nil
end
def redirect_back_or_to(alternate)
redirect_to(session[:return_to] || alternate)
clear_stored_location
end
end
Then you can use something like redirect_back_or_to dashboard_path in your login action.
For some controllers/actions, I don't want to store the location (e.g. the login page). For those I just skip the filter:
class UserController < ApplicationController
skip_after_filter :store_location
end
There's also a page in the Devise wiki on doing this: https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in