0

I have Sample App by Michael Hartl's “Ruby on Rails Tutorial”.

If I click on “Forget Password”, I've got email notification and if click on link “Reset password”, I’ve got redirected to the wrong app that doesn’t exist and I could see only empty page.

https://wrong.com/password_resets/WTk_raloURf8I8sCaXNNkg/edit?email=tatyana_p%70yahoo.com

That wrong app existed earlier but was already deleted. The code as below shows the correct host but the redirection happened to the wrong host.

ENV['SENDGRID_USERNAME'] and ENV['SENDGRID_PASSWORD'] are correct.

I could not find a wrong name of the host anywhere else in code and change it to the correct one.

config/environments/production.rb

config.consider_all_requests_local       = false
config.action_controller.perform_caching = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'correct_host.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
  :address        => 'smtp.sendgrid.net',
  :port           => '587',
  :authentication => :plain,
  :user_name      => ENV['SENDGRID_USERNAME'],
  :password       => ENV['SENDGRID_PASSWORD'],
  :domain         => 'heroku.com',
  :enable_starttls_auto => true
}

If I copy and paste an address that I've got when I click on "Reset password" and changed the wrong address on the right one - I've got the right fields for a password and confirming password.

https://correct_host.herokuapp.com/password_resets/WTk_raloURf8I8sCaXNNkg/edit?email=tatyana_p%70yahoo.com

mechnicov
  • 12,025
  • 4
  • 33
  • 56
T M
  • 95
  • 2
  • 11
  • How do your mailer and your mailer's view look like? – spickermann Mar 30 '19 at 06:18
  • I've got everything exactly as in Michael Hartl tutorial except I could not reset password. I could not figure out where to change the wrong host to the right one. – T M Mar 30 '19 at 08:20
  • Yes, I initially used this wrong host: I git clone from heroku, directory when I've cloned there was empty dir. and I did something about it follow heroku direction and in process I've change the name of the host for the right . Is anything can be done to make it work like commit/anything else? – T M Mar 30 '19 at 08:41
  • Try [this](https://stackoverflow.com/a/44173405/10608621) to solve problem with Git and Heroku – mechnicov Mar 30 '19 at 20:47

2 Answers2

0

If you're using Devise and its default mailer views I'd advise to check your Rails.application.routes.default_url_options (since Devise uses edit_password_url path helper to build url).

neversleep
  • 311
  • 1
  • 7
  • I don't use any Devise and routes.rb don't indicates any path to change. – T M Mar 30 '19 at 07:24
  • 1
    Ok, anyway make sure that `Rails.application.routes.default_url_options` has relevant host. Also, as @spickermann said, it'd be helpful if you show us your mailer's views. – neversleep Mar 30 '19 at 07:34
  • I googled the tutorial you mentioned https://www.railstutorial.org/book/password_reset#cha-password_reset According to chapter 6, Listing 12.9 the mailer's views should be in `app/views/user_mailer` directory, they look fine. Did you check `default_url_options` ? (open console, navigate to project's root directory, type `rails c` [Enter], type `Rails.application.routes.default_url_options` [Enter], the output should looks like `{:host=>"your-domain.com"}`, also what's the output of `Rails.application.routes.url_helpers.edit_password_reset_url('test_token', email: 'test@example.com')` ?) – neversleep Mar 30 '19 at 08:35
  • `rails c -e production` – neversleep Mar 30 '19 at 11:21
  • 2.4.5 :001 > Rails.application.routes.default_url_options => {} it is empty how to add. the right host? Rails.application.routes.url_helpers.edit_password_reset_url('test_token', email: 'test@example.com') ? 2.4.5 :005 > no output and no errors. – T M Mar 30 '19 at 16:34
  • I put it but could not push heroku ttps://git.heroku.com/correct.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/correct.git – T M Mar 30 '19 at 17:25
  • Aww, I missed `?` in ternary operation, it should be `Rails.env.production? ? 'correct_host.herokuapp.com' : 'localhost'`. – neversleep Mar 30 '19 at 17:31
  • I add. only one line . Need to add something else? host: Rails.env.production? 'correct_host.herokuapp.com' : 'localhost' – T M Mar 30 '19 at 17:43
  • it's crashed looks like syntax error again; ake aborted! ! SyntaxError: /tmp/build_b82ef64800b9a08f9b59e512724a9f4b/config/application.rb:30: syntax error, unexpected tSTRING_BEG, expecting '}' ! host: Rails.env.production? 'https://correct.herokuapp.com – T M Mar 30 '19 at 17:59
  • Please see my previous comment (I missed question mark in ternary operation). – neversleep Mar 30 '19 at 18:03
  • I put second ? but app.crashed ... Rails.application.routes.default_url_options = { host: Rails.env.production? ? 'correct_host.herokuapp.com' : 'localhost' } – T M Mar 30 '19 at 18:21
  • It crashed because of syntax error? Could you show the error log? You can use https://pastebin.com if it's too long. – neversleep Mar 30 '19 at 18:31
  • Process exited with status 1 2019-03-30T19:29:17.725955+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=correct.herokuapp.com request_id=683897b5-53fd-4bf3-810c-d8179b408809 fwd="108.211.182.6" dyno= connect= service= status=50 – T M Mar 30 '19 at 19:56
  • @TM, stop crash your app. You don't need to change that. Your problem is that your local file and file on Heroku server are different. Rollback all your changes and carefully commit changes of right host – mechnicov Mar 30 '19 at 20:07
0

You need to make commit for right host

First go to your master branch

git checkout master

Then edit your config/environments/production.rb with right host.

And then

git add config/environments/production.rb
git commit -m "Right host"
git push heroku
mechnicov
  • 12,025
  • 4
  • 33
  • 56
  • it said that nothing to commit and everything up-to-date. I need to change wrong host to the right one and those command change nothing. – T M Mar 30 '19 at 15:46
  • Actually it was on master. But it doesn't solve problem since in this file production.rb the host is correct but it still go the wrong when I try to reset password. – T M Mar 30 '19 at 16:21
  • @TM, type `heroku run bash` and then `cat config/environments/production.rb`. And check that host is right – mechnicov Mar 30 '19 at 19:03
  • there is wrong host. but when I've opened config/environments/production.rb - there is the right one.... – T M Mar 30 '19 at 19:49
  • So you have to do commit. That's your problem – mechnicov Mar 30 '19 at 19:57
  • And you don't need to change application_routes – mechnicov Mar 30 '19 at 19:58
  • I be able change host using those command but after changing it the app. got other error...but it is the different question:) – T M Apr 01 '19 at 00:35