What I'm getting after sending invite to the user:
/users/invitation/accept.37?invitation=_token=3DpoDuVJ5EJcqmHAmbCJTz
What It should be:
/users/invitation/accept.37?invitation_token=3DpoDuVJ5EJcqmHAmbCJTz
I tried to see if the problem was from routes, or maybe from the url but the url is being mounted this way:
<%= accept_invitation_url(#resource, invitation_token: #token) %>
Related
I'm following Mike Hartl's Rails tutorial & ran into an issue when creating email templates. (Please note the tutorial is based on Rails 5.0.1, while I'm plowing ahead with Rails 5.1.1.)
The tutorial uses :activation_token & :activation_digest attributes to handle the security risks of signup URLs, and a :create_activation_digest hook to set their values before creating the User model.
Here's the mailer view template:
<%= link_to "Activate", edit_account_activation_url(#user.activation_token, email: #user.email) %>
The issue appears to be telling Mailer to use the value of :activation_token in the :id field of the route. (A URL definition error)
Here's the route definition, from rails routes:
edit_account_activation GET /account_activations/:id/edit(.:format) account_activations#edit
The error feedback:
No route matches {:action=>"edit", :controller=>"account_activations", :email=>"test7#example.com", :format=>nil, :id=>nil}, possible unmatched constraints: [:id]
I've tried hard-coding id: #user.activation_token in the mailer template, to no avail.
This seems like a easy one, but I'm stumped and a little worried that I'm overlooking something hidden in the transition from Rails 5.0.x to 5.1.x. Any ideas?
You are getting this error because in your config/routes.rb file, you GET /account_activations/:id/edit. That makes it necessary to send an ID which you don't want/need to do. Now I know that Rails Tutorial uses :id for token. But you're not defining id: in your link. So either you need to change the route, or change the link.
<%= link_to "Activate", edit_account_activation_url(id: #user.activation_token, email: #user.email) %>
Notice I define id:. Normally outside this tutorial though, you should consider changing your route to GET /account_activations/edit/:token and then look up the user by token.
Thanks all,
But the error was related to how I defined the :activation_token hook in the User model. All tests now pass.
Suddenly the invitation tokens of Devise invitable are not valid anymore.
I am sending emails containing a link link this:
<url>/users/invitation/accept?invitation_token=Yr4PWJQNTTu1xP8sU5q5
The link in the email view is like this:
= link_to "accept invitation", accept_invitation_url(#user, :invitation_token => #user.invitation_token)
But I see this error:
The invitation token provided is not valid!
What is going wrong here? It worked until recently and to my knowledge nothing has changed in this area.
Edit: when using :invitation_token => #token or :invitation_token => #user.raw_invitation_token, it shows an URL without invitation_token in the email:
<url>/users/invitation/accept
I'm using:
devise (3.5.2)
devise_invitable (1.5.5)
Regardless of what I have tried and I have looked through this Github thread, I keep getting the error The invitation token provided is not valid!
I have the form embedded onto a separate page on my website and the invitation is sending, but the token seems to be wrong.
I do have this line in my mailer code
<p><%= link_to I18n.t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(#resource, :invitation_token => #token) %></p>
I am also using a custom controller, but don't yet have anything in it.
I have the following email that gets sent via Devise after I create a new admin.
<p>Welcome <%= #email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', "http://admin.myapp.com/devise_admin/admins/confirmation?confirmation_token=#{#token}" %></p>
The issue I'm having is that even though I explicitly list http://admin.myapp.com... as my subdomain. In the actual email, the link takes me to http://www.myapp.com...
How is devise overwriting my subdomain when I've hardcoded it? Is it perhaps not using this view to generate the email?
There is a host configuration in the devise initializer
Actually its in the environments/[ENVIRONMENT] files
config.action_mailer.default_url_options = {host: "localhost",port: 3000}
I am using Ruby on Rails 3.1.0 and I would like to properly generate URLs in HTML email messages. In my environment file I set
config.action_mailer.default_url_options = { :host => 'my_site.org' }
In the email view file (.html.erb) I state
<%= link_to #user.name, users_url(#user) %>
When I go to see the received email the generated URL is http://users/1, of course no correct. So, how can I generate correct URLs in mailer templates so to have http://my_site.org/users/1 links in body messages?
I also tryed to set the default_url_options in my mailer.rb file
class MyCustom::Mailer < ActionMailer::Base
default_url_options[:host] = 'my_site.org'
def test_sending
...
end
end
but it doesn't work.
users_path is the relative path (/users/1). For an email, you want the absolute path, so use users_url(#user), which will give http://myapp.com/users/1 instead.
your action_mailer setting is correct.
But you should be using _url and not _path for the link_to,
<%= link_to #user.name, users_url(#user) %>
See that you set the config option. To be sure it uses the absolute path use:
<%= link_to, "My Profile", users_url(:only_path => false, #user) %>
OR set the host specifically in the link:
<%= link_to, "My Profile", users_url(:host => "example.com", #user) %>
It is explained here:
ActionView Helpers