I use Devise (1.4.8) for my User model and have been trying to implement a simple beta invitation feature (Rails 3.0.7), following Ryan Bates's railscast.
I can't get the [new] method of my devise model's controller to recognize the invitation token. I suspect this is because I am not succesfully overriding the registrations controller of Devise.
I am assuming instead of the using the user_controller for passing variables from registration form, I have to override devise's registrations controller. So my registrations_controller.rb in the root of controllers folder:
class RegistrationsController < Devise::RegistrationsController
def new
super
@user = User.new(:invitation_token => params[:invitation_token])
@user.email = @user.invitation.recipient_email if @user.invitation
end
end
In routes.rb:
devise_for :users, :controllers => {:registrations => 'registrations'} do
get 'users/sign_up/:invitation_token' => 'devise/registrations#new', :as => "new_user_registration"
end
In invitation_controller.rb
Mailer.invitation(@invitation, new_user_registration_url+"/#{@invitation.token}").deliver
How I can override Devise's registration controller and pass the :invitation_token successfully from Devise's new user form?
Upon some more research, I found others running into a similar problem:
The real issue was I was trying to pass a variable to one of Omniauth's callback methods. I was not able to figure out how to do that. As a workaround, I ended up using a session variable and accessed it from within the Omniauth callback method.
Not very elegant, but did the trick.