Devise has a redirect hook for after sign in that you can override in your application controller to accomplish this. First you need to set the devise path to nil with:
def stored_location_for(resource)
nil
end
Then you can assign your redirect like so:
def after_sign_in_path_for(resource)
#path_to_redirect_to
end
And that's all there is to changing the redirect after loggin a user in.
Edit
I took a more in depth look at your code and found the login issue you were seeing. In you new session page you were having the login text box point to :username
instead of :login
, so change
<%= f.text_field :username %></div>
to this
<%= f.text_field :login %></div>
and that should then solve your login issue. I also noticed that in your Devise initializer file you were setting authentication keys on both :login
and :email
. This is not best practice for Devise and it is recommended that you change it to be strictly login.
I had a similar issue where I needed to redirect to the signup if the user was not logged in.
I fixed it by adding a method to the application_controller.rb and using it as a before filter in the other controllers.
Keep in mind that is is more of a temporary solution because it skips a bunch of deviseĀ“s abstractions.
before_filter :auth_user
def auth_user
redirect_to new_user_registration_url unless user_signed_in?
end
Best Answer
Well there are two ways of testing it one in the unit level by writing tests in the controllers that inherit the application controller. The code will look something like
For cucumber you should probably write a step to do the login and assert if u are on the expected after sign_in page.