Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token, :redirect_to => stored_location_for(@resource)) %>
- def show
- if params[:redirect_to]
- session["user_return_to"] = params[:redirect_to]
- end
- super
- end
- def stored_location_for(resource_or_scope)
- scope = Devise::Mapping.find_scope!(resource_or_scope)
- session.delete("#{scope}_return_to")
- end
- class Users::ConfirmationsController < Devise::ConfirmationsController
- before_filter :set_redirect_location, :only => :show
- def set_redirect_location
- session["user_return_to"] = params[:redirect_to] if params[:redirect_to]
- end
- end
- devise_for :users,
- :controllers => { :confirmations => 'users/confirmations'}
- class User < ActiveRecord::Base
- …
- attr_accessor :return_to
- …
- end
- class RegistrationsController < Devise::RegistrationsController
- def create
- params[:user][:return_to] = session[:user_return_to] if session[:user_return_to]
- …
- super
- end
- end
- <% if @resource.return_to %>
- <%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token, :redirect_to => @resource.return_to) %>
- <% else %>
- <%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>
- <% end %>
- class ConfirmationsController < Devise::ConfirmationsController
- before_filter :set_redirect_location, :only => :show
- def set_redirect_location
- session[:user_return_to] = params[:redirect_to] if params[:redirect_to]
- end
- end
- class ConfirmationsController < Devise::ConfirmationsController
- def create
- self.resource = resource_class.send_confirmation_instructions(params[resource_name],session[:user_return_to])
- if resource.errors.empty?
- set_flash_message(:notice, :send_instructions) if is_navigational_format?
- respond_with resource, :location => after_resending_confirmation_instructions_path_for(resource_name)
- else
- respond_with_navigational(resource){ render_with_scope :new }
- end
- end
- end
- class User < ActiveRecord::Base
- def self.send_confirmation_instructions(attributes={},redirect=nil)
- confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
- confirmable.return_to = redirect if confirmable.persisted?
- confirmable.resend_confirmation_token if confirmable.persisted?
- confirmable
- end
- end
Add Comment
Please, Sign In to add comment