Question

In my app I am working on allowing users to send invitations. The invites have tokens. And in the emails I am linking to a signup page with the token in the path. In the mailer's controller I am using:

new_user_registration_url(@invitation.token)

as I saw Ryan Bates do in this railscast. But it appears to be outputting this format:

http://localhost:3000/signup.4a4aebcde29738a39c7f447f58817e49cf9b4cf4

Why is there a "." instead of a "/"?

Update:

I'm using devise and here are the relevant routes. I am not to confident about these; I had struggled a little with it but these seemed to work:

  devise_scope :user do
    get '/signup/:invitation_token' => "registrations#new", :as => :new_user_registration
  end
  devise_for :users, :controllers => { :registrations => "registrations"}, :skip => [:registrations]
  as :user do
    get '/users/cancel' => 'devise/registrations#cancel', :as => :cancel_user_registration
    post '/users' => 'devise/registrations#create', :as => :user_registration
    get '/signup' => 'registrations#new', :as => :new_user_registration
    get '/users/edit' => 'devise/registrations#edit', :as => :edit_user_registration
    put '/users' => 'devise/registrations#update'
    delete '/users' => 'devise/registrations#destroy'
  end
Était-ce utile?

La solution

Wihout routes.rb it's hard to tell but it seems the author has something like:

#in routes.rb
get 'signup' => 'controller#action', as: :new_user_registration

but has to have:

get 'signup/:token' => 'controller#action', as: :new_user_registration

Checking:

# in console
app.new_user_registration_path('ToKeN') # => "/signup/ToKeN"

Autres conseils

If you just pass a string or a symbol as an argument to a path helper, I think it gets interpreted as the format. Try something like the following:

new_user_registration_url(:token => @invitation.token)

or

new_user_registration_url + "/" + @invitation.token
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top