2016-04-22 3 views
7

のホストを設定するには:どこのようなサービスを呼び出すコントローラーでRails.application.routes.url_helpers

Rails.application.routes.url_helpers.something_url 

:私は、URLヘルパーを使用したいMyService.call方法で

MyService.call 

しかし、私はエラーを取得する:私が持っている設定/環境/ development.rbで

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

config.action_mailer.default_url_options = { host: 'localhost:3000' } 
config.action_controller.default_url_options = { host: 'localhost:3000' } 

エラーを報告しないようにするにはどうすればよいですか?

+0

「somewhere in the code」はどこですか?おそらく、これは役立ちます:http://stackoverflow.com/questions/7219732/missing-host-to-link-to-please-provide-host-parameter-or-set-default-url-optio – Nobita

答えて

6

あなたはとして設定ファイルにホストを設定できます。これは、action_maileraction_controllerため、しかしurl_helpersを使用して何のためだけではなく、デフォルトのホストを設定します

Rails.application.routes.default_url_options[:host] = 'your_host'

。ルートヘルパーを使用していつでも

+4

への参照がありますか?これはどこに書かれている?私はしばしば 'action_mailer'のためだけに参照を見つけますが、残りの部分は見つけられません –

2

this threadによると、彼らはdefault_url_optionsActionMailerまたはActionController設定を延期していないと、クラスのdefault_url_options方法があるだろうと期待されます。これは私のために働いていた:あなたが設定したaction_mailerまたはaction_controller設定によってはを使用することができます

class MyService 
    include Rails.application.routes.url_helpers 

    def call 
    something_url 
    end 

    class << self 
    def default_url_options 
     Rails.application.config.action_mailer.default_url_options 
    end 
    end 
end 

注意を。

関連する問題