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
<h2>Sign in</h2>
<%= 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 2012-11-16 19:32
on 2012-11-16 21:15
On Fri, Nov 16, 2012 at 1:32 PM, Dave Castellano <lists@ruby-forum.com>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/creatin... Hope that helps. Casey
on 2012-11-17 17:47
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"
on 2012-11-17 19:06
On Sat, Nov 17, 2012 at 11:47 AM, Dave Castellano <lists@ruby-forum.com>wrote: > root :to => "home#index" > Nice! That I did not know about. Casey
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.