# Devise question

**URL:** <https://www.ruby-forum.com/t/devise-question/224561>\
**Category:** Rails\
**Created:** [November 16, 2012, 7:32pm UTC](https://www.ruby-forum.com/t/devise-question/224561 "2012-11-16T19:32:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 16, 2012, 7:32pm UTC](https://www.ruby-forum.com/t/devise-question/224561/1 "2012-11-16T19:32:54Z")

</div>

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" %\>

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [November 16, 2012, 9:15pm UTC](https://www.ruby-forum.com/t/devise-question/224561/2 "2012-11-16T21:15:02Z")

</div>

On Fri, Nov 16, 2012 at 1:32 PM, Dave C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)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:

[http://stackoverflow.com/questions/7086583/creating-a-users-show-page-using-devise](http://stackoverflow.com/questions/7086583/creating-a-users-show-page-using-devise)

Hope that helps.

Casey

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [November 17, 2012, 7:06pm UTC](https://www.ruby-forum.com/t/devise-question/224561/3 "2012-11-17T19:06:52Z")

</div>

On Sat, Nov 17, 2012 at 11:47 AM, Dave C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> root :to =\> “home#index”

Nice! That I did not know about.

Casey

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [November 17, 2012, 5:47pm UTC](https://www.ruby-forum.com/t/devise-question/224561/4 "2012-11-17T17:47:23Z")

</div>

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”
