Guest User

Untitled

a guest
Jul 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. <%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token, :redirect_to => stored_location_for(@resource)) %>
  2.  
  3. def show
  4. if params[:redirect_to]
  5. session["user_return_to"] = params[:redirect_to]
  6. end
  7. super
  8.  
  9. end
  10.  
  11. def stored_location_for(resource_or_scope)
  12. scope = Devise::Mapping.find_scope!(resource_or_scope)
  13. session.delete("#{scope}_return_to")
  14. end
  15.  
  16. class Users::ConfirmationsController < Devise::ConfirmationsController
  17. before_filter :set_redirect_location, :only => :show
  18.  
  19. def set_redirect_location
  20. session["user_return_to"] = params[:redirect_to] if params[:redirect_to]
  21. end
  22. end
  23.  
  24. devise_for :users,
  25. :controllers => { :confirmations => 'users/confirmations'}
  26.  
  27. class User < ActiveRecord::Base
  28. attr_accessor :return_to
  29. end
  30.  
  31. class RegistrationsController < Devise::RegistrationsController
  32. def create
  33. params[:user][:return_to] = session[:user_return_to] if session[:user_return_to]
  34. super
  35. end
  36. end
  37.  
  38. <% if @resource.return_to %>
  39. <%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token, :redirect_to => @resource.return_to) %>
  40. <% else %>
  41. <%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>
  42. <% end %>
  43.  
  44. class ConfirmationsController < Devise::ConfirmationsController
  45. before_filter :set_redirect_location, :only => :show
  46.  
  47. def set_redirect_location
  48. session[:user_return_to] = params[:redirect_to] if params[:redirect_to]
  49. end
  50. end
  51.  
  52. class ConfirmationsController < Devise::ConfirmationsController
  53. def create
  54. self.resource = resource_class.send_confirmation_instructions(params[resource_name],session[:user_return_to])
  55.  
  56. if resource.errors.empty?
  57. set_flash_message(:notice, :send_instructions) if is_navigational_format?
  58. respond_with resource, :location => after_resending_confirmation_instructions_path_for(resource_name)
  59. else
  60. respond_with_navigational(resource){ render_with_scope :new }
  61. end
  62. end
  63. end
  64.  
  65. class User < ActiveRecord::Base
  66. def self.send_confirmation_instructions(attributes={},redirect=nil)
  67. confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
  68. confirmable.return_to = redirect if confirmable.persisted?
  69. confirmable.resend_confirmation_token if confirmable.persisted?
  70. confirmable
  71. end
  72. end
Add Comment
Please, Sign In to add comment