Devise question

Using Devise and would like to redirect to a different page upon
sign-in. There is no controller for Devise sessions, so my question is
where is the method associated with a new session so I can redirect
signed-in user to a different page (or can I do it in the view below?)?
Currently directing to Home/index and want to redirect to Users/show

Sign in

<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => {:class => 'form-vertical' }) do |f| %> <%= f.input :email, :autofocus => true %> <%= f.input :password %> <%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %> <%= f.button :submit, "Sign in", :class => 'btn-primary' %> <% end %> <%= render "devise/shared/links" %>

On Fri, Nov 16, 2012 at 1:32 PM, Dave C.
[email protected]wrote:

<%= f.input :email, :autofocus => true %>
<%= f.input :password %>
<%= f.input :remember_me, :as => :boolean if
devise_mapping.rememberable? %>
<%= f.button :submit, “Sign in”, :class => ‘btn-primary’ %>
<% end %>
<%= render “devise/shared/links” %>

I ended up doing this:

Create a sessions_helper module:

module SessionsHelper

private

def set_return_path
# Below is the proper way to set a redirect after login with devise
session[:user_return_to] = request.fullpath # This will just
redirect
back to the last page the user was on.
# You
can change it to the Users/show path once it exists.

end

end

That works after sign in.

If you need to redirect to a specific page after a user updates their
account you need to have
a registrations controller:

class RegistrationsController < Devise::RegistrationsController

protected

Customize the Devise after_update_path_for() for redirect to

previous
page after edit
def after_update_path_for(resource_or_scope)
case resource_or_scope
when :user, User
store_location = session[:user_return_to]
(store_location.nil?) ? “/” : store_location.to_s
else
super
end
end

end

Looks like Devise doesn’t automatically have a Users/show view:

 new_user_session GET

/users/sign_in(.:format) devise/sessions#new
user_session POST
/users/sign_in(.:format) devise/sessions#create
destroy_user_session GET
/users/sign_out(.:format)
devise/sessions#destroy
user_password POST
/users/password(.:format)
devise/passwords#create
new_user_password GET
/users/password/new(.:format) devise/passwords#new
edit_user_password GET
/users/password/edit(.:format) devise/passwords#edit
PUT
/users/password(.:format)
devise/passwords#update
cancel_user_registration GET
/users/cancel(.:format) registrations#cancel
user_registration POST
/users(.:format) registrations#create
new_user_registration GET
/users/sign_up(.:format) registrations#new
edit_user_registration GET
/users/edit(.:format) registrations#edit
PUT
/users(.:format) registrations#update
DELETE
/users(.:format) registrations#destroy
user_unlock POST
/users/unlock(.:format) devise/unlocks#create
new_user_unlock GET
/users/unlock/new(.:format) devise/unlocks#new
GET
/users/unlock(.:format) devise/unlocks#show

Looks like this Stack Overflow question answers how to do that:

Hope that helps.

Casey

On Sat, Nov 17, 2012 at 11:47 AM, Dave C.
[email protected]wrote:

root :to => “home#index”

Nice! That I did not know about.

Casey

Thank you !

I also found this which seems to work well…

routes.rb:

authenticated :user do
root :to => ‘users#show’
end

root :to => “home#index”