On Fri, Nov 16, 2012 at 1:32 PM, Dave Castellano
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:
> 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" %>
>
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
Hope that helps.
Casey
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.