muichkine
muichkine

Reputation: 2940

rails 3 absolute link to generated url

I am looking into generating urls which look like https://mywebsite.com/user/check_email_confirmation/46cee41bc2044104aff8cf7746687ea8

for the famous "please click this link to confirm your email".

So I have a route which I intend to use for this in my routes.rb:

  resources :user do
    collection do
      get  'check_email_confirmation/:generated_url', :to => 'user#check_email_confirmation'
    end
  end

Now, my trouble is to generate the full address above. I cah generate the SHA (46cee41bc2044104aff8cf7746687ea8) part, but how do I write the "https://mywebsite.com/user/check_email_confirmation/" part in my view?

Added view's code:

<p>Please click <%= url_for(:action => 'check_email_confirmation', :controller => 'user', :only_path => false, :id => @confirmation_url) %> to confirm your e-mail address.</p>

Upvotes: 1

Views: 284

Answers (2)

chaitanya
chaitanya

Reputation: 1974

get "check_email_confirmation/:id" => "users#check_email_confirmation", :as => "check_email_confirmation" 

Upvotes: 0

Mailo Světel
Mailo Světel

Reputation: 25991

Replace id: with generated_url:.

You could also simplify the url_foring with naming the route by as: in routes

get  'check_email_confirmation/:generated_url', to: 'user#check_email_confirmation', as: :confirmation

More on this at http://viget.com/extend/rails-named-routes-path-vs-url

Upvotes: 1

Related Questions