How to include full-path in Rails 3 link_to statement?

后端 未结 6 553
说谎
说谎 2021-01-17 10:17

I am trying to put a Rails link_to statement inside a Mailer email that includes the full-path (ie - http://localhost/contacts/id/confirm). The link_to statement that I am

6条回答
  •  一生所求
    2021-01-17 10:56

    Because mailers aren't run inside the response stack, they have no idea what host they were called from: that's why you're running into this error. It's easy to fix, change the code to include the host:

    <%= link_to "here", :controller => "contacts", :action => "confirm",
    :only_path => false, :id => 17, :host => "example.com" %>
    

    You can also set the default host on a per-application basis inside of your application.rb (or any of your environments) by specifying this:

    config.action_mailer.default_url_options = { :host => "example.com" }
    

    For the full documentation on ActionMailer and why this problem occurs, check out the ActionMailer documentation.

提交回复
热议问题