RailsCasts Pro episodes are now free!

Learn more or hide this

Engin Erdogan's Profile

GitHub User: erdogan

Site: http://engin-erdogan.com

Comments by Engin Erdogan

Avatar

I use Devise and have been trying to implement invitations. I am having an issues, can you help?

I can't get my devise model (user) to recognize the :invitation_token in the (new) method as pointed out in the episode, the hidden_field in the form never receives the invitation_token. It does get passed as a parameter though, I see it in logs.

Placing the :invitation_token and email assignments in the user_controller didn't work. I also created a registrations_controller and tried to override the new method. This didn't work either:

ruby
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

Here is my relevant routes.rb line:

ruby
devise_for :users, :controllers => {:registrations => 'registrations'} do
  get 'users/sign_up/:invitation_token' => 'devise/registrations#new', :as => "new_user_registration"
end

And invitation_controller.rb

ruby
Mailer.invitation(@invitation, new_user_registration_url+"/#{@invitation.token}").deliver

Any suggestions greatly appreciated, thank you.