1

I am very confused with how to provide the default_url_options. I am getting this error

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

I am using spreecommerce which uses devise for authentication. This error is occurring durring password reset on my development environment. I have not tested it in a production environment yet. I am using this in my environments/development

config.default_url_options = { host: 'localhost:3000' }
Rails.application.routes.default_url_options[:host] = 'localhost:3000'

in my rails console when I do Rails.application.routes.default_url_options I get {:host => Rails.application.config.domain}. The same thing happends when I do Rails.applicaiton.default_url_options

None of the solutions I have found have worked.

Sam M
  • 640
  • 1
  • 8
  • 18
  • I stuck with the same issue. Couple days ago adding default_url_options solved my problem, but not now. – Jakub Apr 04 '17 at 16:25
  • It works for me on a different computer. I have no idea why it is broken. – Sam M Apr 04 '17 at 17:19
  • Here is what I can see: my option variable (host is nil) `{:controller=>"spree/user_confirmations", :action=>"create", :host=>nil, :port=>3000, :confirmation_token=>2904397, :path=>"/user/spree_user/confirmation", :script_name=>"/", :params=>{:confirmation_token=>2904397}, :user=>nil, :password=>nil}` and `>> Rails.application.config.action_mailer.default_url_options` `=> {:host=>"localhost", :port=>3000}` but `Rails.application.action_mailer.default_url_options` is empty – Jakub Apr 04 '17 at 18:10
  • `config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } `helped me – talal7860 Nov 21 '17 at 23:23

1 Answers1

0

TL;DR In my case Spree::Store.current vanished - I had to recreate it.


I tried set default_url_options for routes and into environments. But with no luck.

So I got into spree_auth_devise-3.1.0 gem source code:

@confirmation_url = spree.spree_user_confirmation_url(:confirmation_token => token, :host => Spree::Store.current.url)

So for the host, it's using Spree::Store. Then I went into console and got that my Spree::Store.current is empty:

(byebug) Spree::Store.current.url
nil

So simply creating a store with dummy data resolved my problem.

store = Spree::Store.new
store.name = 'test'
store.url = 'http://localhost:3000'
store.code = 'spree'
store.default = true
store.save
Jakub
  • 733
  • 5
  • 20