I am creating an application (the User has many groups) in which an existing user can send invitations to invite people to join the group. If sign_up url has an invitation token, I need to override the default controller action to create.
routes.rb
devise_for :users do match '/users/sign_out', :to => 'devise/sessions#destroy' match '/users/sign_up/:invitation_token', :to => 'registrations#create'
registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
end
Magazines
Started GET "/users/sign_up/83003a4fab004ef4c1934c15f7215e8dc6a57718" for 127.0.0.1 at 2012-12-11 14:53:18 Processing by RegistrationsController#create as HTML Parameters: {"invitation_token"=>"83003a4fab004ef4c1934c15f7215e8dc6a57718"} SQL (0.1ms) BEGIN User Exists (1.0ms) SELECT 1 AS one FROM `users` WHERE `users`.`name` IS NULL LIMIT 1 User Exists (0.1ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = '' LIMIT 1 (0.1ms) ROLLBACK
This redirects me to the sign_up path, but performs checks to load the page.
Email can't be blank Password can't be blank Name can't be blank
Logs after sign_up with previous page
Started POST "/users" for 127.0.0.1 at 2012-12-11 14:56:37 +0530 Processing by Devise::RegistrationsController#create as HTML Parameters: {"utf8"=>"β", "authenticity_token"=>"gUmNDb1Sj/ZVnXMG8t/Av0QlAYg7nAMTsSU5ZBW+s60=", "user"=>{"name"=>"Prashanth2", "email"=>" sample@sampleee.com ", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"} SQL (0.1ms) BEGIN User Exists (0.4ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY ' sample@sampleee.com ' LIMIT 1 User Exists (0.3ms) SELECT 1 AS one FROM `users` WHERE `users`.`name` = 'Prashanth2' LIMIT 1 User Exists (0.2ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = ' sample@sampleee.com ' LIMIT 1 SQL (1.1ms) INSERT INTO `users` (`created_at`, `current_sign_in_at`, `current_sign_in_ip`, `email`, `encrypted_password`, `invitation_id`, `invitation_limit`, `last_sign_in_at`, `last_sign_in_ip`, `name`, `remember_created_at`, `reset_password_sent_at`, `reset_password_token`, `sign_in_count`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["created_at", Tue, 11 Dec 2012 09:26:37 UTC +00:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["email", " sample@sampleee.com "], ["encrypted_password", "$2a$10$jcaLbYWNqp2sbUlAZWb38.Ls7Ku90ImOQ11k0fxJSq/mD4Zm2U1JO"], ["invitation_id", nil], ["invitation_limit", 5], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["name", "Prashanth2"], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["sign_in_count", 0], ["updated_at", Tue, 11 Dec 2012 09:26:37 UTC +00:00]] (108.5ms) COMMIT SQL (0.1ms) BEGIN (0.3ms) UPDATE `users` SET `last_sign_in_at` = '2012-12-11 09:26:38', `current_sign_in_at` = '2012-12-11 09:26:38', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2012-12-11 09:26:38' WHERE `users`.`id` = 12 (127.8ms) COMMIT