I'm writing a rails3 app using authlogic and authlogic-oid to allow the user to login and register using their LinkedIn account. I'm able to call out to LinkedIn to authenticate but the issue I'm having is that when the call returns to my rails app, it is calling a GET on /user_sessions and invoking the index controller instead of executing the remainder of the create controller. Here's the controller:
# POST /user_sessions
def create
@user_session = UserSession.new(params[:user_session])
@user_session.save do |result| # <-- redirects to api.linkedin.com here
if result
flash[:success] = "Login successful!"
redirect_back_or @user_session.user_path
else
flash.now[:error] = "Invalid username/password combination."
@title = "Sign in"
render 开发者_开发知识库'new'
end
end
end
Everything works great until if result
which never gets called because the program resumes execution in the index
controller instead of picking up where it left off. Any ideas on how to fix this would be greatly appreciated.
Edit: it seems my assumption that the controller was not completing execution was wrong. I've put in a bunch of debug statements and learned that the the program does resume execution in this controller after @user_session.save but it is not executing either condition on the if statement. I'm very confused on this one.
if you don't want to use index
method in your UserSessionsController
then write this: resources :user_session
in your route.rb . If you'll use singular form then route can map CRUD (create, read, update, delete) and if you'll use plural of it then it will bind CRUD with index
method of your controller.
精彩评论