Rails and Devise Missing link to host

361 Views Asked by At

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.

1

There are 1 best solutions below

0
Jakub On

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