I am sending the password reset instructions via the default devise password reset instructions email. When I click on the change password it routes me to the localhost:3000 in my local machine but in production it is routing to some ip. I think it is of the cloud server we are hosting on, how to change this to the domain name ?
This is the devise password reset instructions:
<p>Hello <%= #resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(#resource, reset_password_token: #token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
How to change this do I have to set the url hardcoded to the domains ? Because we have a staging and production environment.
Here I've just given a quick answer on sending emails in production in general.
In your particular case you are looking for putting the following code in production.rb:
config.action_mailer.default_url_options = { :host => 'YOUR-APP-NAME.herokuapp.com', :protocol => 'https' }
If you have more than one environment, you configure each environment separately, right? So for staging you would have something like config/environments/staging.rb and configure it there.
More details on action mailer
Related
I've write a RoR application and I use Devise for some user management.
I've already configure my application to send email for password recovery and I use the following code in my reset_password_instruction.html.erb:
<p><%= link_to 'Modify password', edit_password_url(#resource, reset_password_token: #token) %></p>
In my config environment files I have defined: config.action_mailer.default_url_options = { :host => 'app_url.com' }.
When the application send a recovery email, it attach an url like this:
app_url.comuser insted of app_url.com/user.
What did I miss?
From the rails console, I see the url like it is suppposed to be.
<p><a href=3D"http://app_url.com/users/password/edit?reset_password_=token=3D47da8a08bd3d4asdfadfasdfa3eb9422388467adccfe095f058ca2a3352b12"=>Modify password</a></p>
I am using rails 4 and ruby 2. I have implemented login using devise. My problem is forgot password is not working on heroku but working on local. After receiving the mail when i clicked on "Change my password" link, it redirects to https://www.heroku.com/ page. How can I solve this issue? please help me if any one have any idea.
Codes:
reset_password_instructions.html.erb:
<p>Hello <%= #resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(#resource, reset_password_token: #resource.reset_password_token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
Check if you configured your server's url in your config/application.rb:
config.action_mailer.default_url_options = { host: 'your.example.com' }
Find more details in the Rails Guide about Mailers.
In you config/environments/production.rb file, you should have a looking like
config.action_mailer.default_url_options = { :host => "http://eee.com" }
It defines the url used by action mailer when resolving url using the Rails url helpers. So If you set this value or change it, it should change the result.
The links that are sent in the password reset and account activation are being sent in the email, but when I click on them, they are not being redirected to my Heroku app and the browser gets stuck at "about:blank". Am I missing something? They look like this:
Reset password
Here is my app/views/user_mailer/password_reset.html.erb
<h1>Password reset</h1>
<p>To reset your password click the link below:</p>
<%= link_to "Reset password", edit_password_reset_url(#user.reset_token,
email: #user.email) %>
<p>This link will expire in two hours.</p>
<p>
If you did not request your password to be reset, please ignore this email and
your password will stay as it is.
</p>
Looks like the URL that you pass over to SendGrid is http://<your+heroku+app>.herokuapp.com/password_resets/..., so you'd need to make sure you specify your app's name instead of having http://<your+heroku+app>. If you're using SMTP, check to see if you have your config.action_mailer.default_url_options (in config/production.rb) setup properly:
config.action_mailer.default_url_options = { :host => 'http://appname.herokuapp.com' }
did same error and felt so LOL when I realized the solution:
check your config/environments/production.rb Listing 10.56
update host = '<your+heroku+app>.herokuapp.com' with your APP's name (in my case was host = 'twitterdave.herokuapp.com' )
Let me know if it helps
I'm using Devise for authentication with a Rails 4 app and am having issues with the password reset. Locally, everything works fine, when I paste the reset link in (i.e. localhost:3000/users/password/edit?reset_password_token=e_f3ZpqrE_rTBZmKJk_E) it works as expected.
On Heroku however, Devise seems to not even notice the :reset_password_token param, and automatically redirect to /users/signin with the notice "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
Here's is an example of the link that is being generated: http://mysite.io/users/password/edit?reset_password_token=anzYNreZEcz4-dtZy5Uf
I even overrode the assert_reset_token_passed method in my own controller to check if params[:reset_password_token] was actually blank, and for some reason it is, rails is not pulling this out of the url. Here's my modified method:
def assert_reset_token_passed
logger.info params[:reset_password_token] #This is blank somehow
if params[:reset_password_token].blank?
set_flash_message(:alert, :no_token)
redirect_to new_session_path(resource_name) #This is where the redirect happens
end
end
Any help would be much appreciated.
I was having the exact same issue. The fix for me was to update the config.action_mailer.default_url_options in production.rb to include the full host (in my case 'www.mydomain.com' vs 'mydomain.com').
To clarify, it used to be
config.action_mailer.default_url_options = { :host => 'mydomain.com' }
and now it's
config.action_mailer.default_url_options = { :host => 'www.mydomain.com' }
I'm having problems when resetting a password using Devise.
When I click on 'Send me reset password instructions', I get:
ArgumentError at /users/password
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
It says that the problem is in /views/devise/mailer/reset_password_instructions.html.erb on line 5.
On line 5 in that file there is:
<p><%= link_to 'Change my password', edit_password_url(#resource, :reset_password_token => #resource.reset_password_token) %></p>
I have no idea how to setup a mailer in Rails although I have tried to. Can anybody help me with this?
Finally, you need to set up default url options for the mailer in each
environment. Here is the configuration for "config/environments/development.rb":
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
You need to specify the host so it can be shown in the confimation email.
You can create a default filter like this:
# application_controller.rb
before_filter :mailer_set_url_options
...
def mailer_set_url_options
ActionMailer::Base.default_url_options[:host] = request.host_with_port
end