I have several ajax elements that require authorization, but for various
reasons, they can’t pass session[original_uri] to the redirect on user
log in. I’m trying to hack in a uri by passing a param to the login
page.
I can see that the param is passing into the login page, but for
whatever reason, no matter what I do, the user is redirected to the
homepage after login.
Would anyone have any ideas? thanks soo much!
-Mario
#code from show.rhtml
if current_user #ajax code
else
link_to “vote up”, login_url(:referrer_uri => request.request_uri) %>
end
#Controller
def create
uri ||= params[:referrer_uri] #pull in hacked original_uri
uri ||= session[:original_uri] #pull in sessions's original uri
uri ||= homepage_url #default to homepage
render :action => :new and return true if request.get?
if params[:user_name] and params[:password] and user =
User.authenticate(params[:user_name], params[:password])
session[:user_id] = user.id
session[:original_uri] = nil
redirect_to(uri) and return true
else
flash[:failure] = “Invalid username or password.”
redirect_to login_url and return false
end
end
i’ve used that thing several times, as you want it and it works fine.
seems to me, it didn’t reach the redirect_to(uri) line for some reason
or uri is not set to the right path in the first lines of your action
check it that way:
add
logger.info “URI: #{uri}”
behind those “uri ||=” lines
and something the like before your redirects. then check in
development.log, what actually is in those vars and which parts of your
code are reached.
That helped me track down my problem. Apparently, the uri wasn’t
getting carried over the the create action in my session controller. So
I just added the param to my login form.
That helped me track down my problem. Apparently, the uri wasn’t
getting carried over the the create action in my session controller. So
I just added the param to my login form.