How to set config.action_controller.default_url_options = {:host = '#''} on per environment basis

please provide the host parameter set default_url_options
config actioncontroller asset_host
rails default_url_options https
set rails host
config hosts rails
raise_on_unfiltered_parameters
missing host to link to active storage
config assets raise_runtime_errors

Right now I'm using this which works for the development host, but I have to manually change the {:host => ""} code when I move to production.

post.rb
def share_all
  url =  Rails.application.routes.url_helpers.post_url(self, :host => 'localhost:3000')
  if user.authentications.where(:provider => 'twitter').any?
    user.twitter_share(url)  
  end
end

I'd like to use this and then define the default_url_options per environment:

post.rb
def share_all
  url =  Rails.application.routes.url_helpers.post_url(self)
  if user.authentications.where(:provider => 'twitter').any?
    user.twitter_share(url)  
  end
end

I've tried adding this to my config/environments/development.rb but I still get the "Missing host to link to! Please provide :host parameter or set default_url_options[:host]" error

development.rb
config.action_controller.default_url_options = {:host => "localhost:3000"}

And I even tried it this way:

development.rb
config.action_controller.default_url_options = {:host => "localhost", :port => "3000"}

EDIT:

I've now also followed this and still the same error guide http://edgeguides.rubyonrails.org/action_controller_overview.html#default_url_options

application controller
class ApplicationController < ActionController::Base
  protect_from_forgery
  include ApplicationHelper
  def default_url_options
    if Rails.env.production?
      { :host => "example.com"}
    else
      {:host => "example1.com"}
    end
  end
end

This is driving me crazy, what am I missing here???


Okay I figured it out the correct way to write it is

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

:)

routes.default_url_options should be read from config , default_url_options from config.action_controller.default_url_options I cannot and would not detect and define which host and port should  Another way is to set it like this # config/production.rb config.action_controller.default_url_options = { host: 'myproduction.com' }


Inherit your Application's default_url_options from ActionMailer.

You want to keep things as DRY as possible so, ideally, you don't want to hard code your host and port in multiple places for the same environment, unless your ActionMailer actually uses a different host and port than the rest of your Application.

To set the default_url_options for your entire Application, simply add the following line to your config/environment.rb file (changing MyApp to your app's name):

# Set the default host and port to be the same as Action Mailer.
MyApp::Application.default_url_options = MyApp::Application.config.action_mailer.default_url_options

This will fix your problem and automatically set your Application's default_url_options to the same as your config.action_mailer.default_url_options:

$ MyApp::Application.config.action_mailer.default_url_options
#=> {:host=>"lvh.me", :port=>"3000"}

$ MyApp::Application.default_url_options
#=> {:host=>"lvh.me", :port=>"3000"}

Unable to set default_url_options on per environment basis, end end. I've tried adding this to my config/environments/development.rb : development.rb. config.action_controller.default_url_options = {:host  I'm currently facing a situation where I need to use URL helpers from an ActiveJob (I generating picture from an in-app page) and it does not read the default_url_options from config.action_controller.default_url_options even if it is specified to the active Rails.env. However, at the Job, I cannot and would not detect and define which host and


You have to restart your server before the changes to this file takes effect.

Configuring Rails Applications, development.rb. config.action_controller.default_url_options = {:host => "​localhost:3000"}. And I even tried it this way:  61 How to set config.action_controller.default_url_options = {:host = '#''} on per environment basis 36 CSS: styled a checkbox to look like a button, is there a hover? 27 Rails 3 / PhoneGap: Converting a Rails app into an Phonegap iOS app?


config.action_mailer.default_url_options = { :host => "your host" }

for instance your host localhost:3000

you can put this in test.rb, development.rb, production.rb files host could be different from environment to environment

Como definir config.action_controller.default_url_options = {: Host , Agora eu estou usando isso que funciona para o host de desenvolvimento, mas Como definir config.action_controller.default_url_options = {: Host = '#' '} por base de ambiente Set the default Host and port to be the same as Action Mailer​. You need to add the following line at every environment: config.action_mailer.default_url_options = { :host => "yourhost" } That way, it can work in all environments and could be different from environment to environment.


I know this is an old thread, but I ran into this with Ruby 2.6.3 and Rails 5.2.3. The behavior I was seeing was basically that every path I added would fail with Error during failsafe response: undefined method 'empty?' for nil:NilClass. In production it worked fine, but in my development environment, I would get the error mentioned above.


The fix for me was add this to controllers/application_controller.rb:

def default_url_options
  if Rails.env.production?
    Rails.application.routes.default_url_options = { host: "www.production-domain.com", protocol: 'https' }
  elsif Rails.env.development?
    Rails.application.routes.default_url_options = { host: 'localhost:3000', protocol: 'http' }
  end
end

I was then able to run my development environment on my local.

Would like to understand why Rails/RSpec is ignoring config , Please provide the :host parameter, set default_url_options[:host], or set :​only_path to true test (byebug) ActionMailer::Base.default_url_options {:host=>​nil} config.action_controller.default_url_options = { host: 'http://localhost:8080' }. ---edit  config.action_mailer.default_url_options = { :host => 'localhost' } Make sure you change host to your production url and keep it localhost for development. This is for the mailer, it needs a default email to send out notices such as confirmations etc


Rails' many default_url_options, I have read so many different ways to set default_url_options. config.​action_controller.default_url_options= {:protocol => 'https'} # Works in  Action Controller OverviewIn this guide you will learn how controllers work and how they fit into the request cycle in your application.After reading this guide, you will know: How to follow the flow of a request through a controller. How to restrict parameters passed to your controller. How and why to store data in the session or cookies. How to work with filters to execute code during


Active Admin with reverse proxy pulling server URL instead of , I have a Ruby on Rails server set up using a reverse proxy for routing config.​action_controller.default_url_options = {:host=>"api.site.com"}. I think a simple solution would be for redirect_to some_path to use the host from config.action_controller.default_url_options if it exists (of course, won't protect apps that don't have it set). redirect_to some_url does not have the same issue.


Please provide the :host parameter, set default_url_options[:host], or set :only_path to true The reason your proposed solution in #1276 appears to work is simply because the example's default_url_options is nil and so it falls back to the routes which you have customized in the spec/rails_helper.rb .