Forum: Ruby on Rails Getting Hostname in mailer view

0c272b25fa18ac459cdffe24fa570aff?d=identicon&s=25 Vincent Romagnoli (skyporter)
on 2011-01-17 14:34
Hi everyone,

I need to build a url in my mails view. For restfull resources I can use
routing and  "..._url" target. But for custom url I don't know how I
get the hostname of my web app.

I didn't know how I can get get the value specified on
config.action_mailer.default_url_options = {:host =>
"here_my_host_i_want_get" }

Thanks for reply

Vincent
08bbdb4705bfab08daa3a7d607573490?d=identicon&s=25 Tim Shaffer (Guest)
on 2011-01-17 17:03
(Received via mailing list)
I believe you can access it through
ActionMailer::Base.default_url_options[:host]

Or alternately, you can just generate the URL using url_for()
6799ecb7745167d2590d85c4ed25d985?d=identicon&s=25 David Kahn (dkahn)
on 2011-01-17 17:04
(Received via mailing list)
On Mon, Jan 17, 2011 at 7:34 AM, Vincent Romagnoli
<lists@ruby-forum.com>wrote:

> Hi everyone,
>
> I need to build a url in my mails view. For restfull resources I can use
> routing and  "..._url" target. But for custom url I don't know how I
> get the hostname of my web app.
>
> I didn't know how I can get get the value specified on
> config.action_mailer.default_url_options = {:host =>
> "here_my_host_i_want_get" }
>

What I would do is pass it in on your mailer method... you can get the
host
name in your controller: request.host. I see action mailer as a model
essentially so you should not couple it to the session.
0c272b25fa18ac459cdffe24fa570aff?d=identicon&s=25 Vincent Romagnoli (skyporter)
on 2011-01-18 12:11
Tim Shaffer wrote in post #975474:
> I believe you can access it through
> ActionMailer::Base.default_url_options[:host]
>
> Or alternately, you can just generate the URL using url_for()

Yes ActionMailer::Base.default_url_options[:host] work fine.

Thanks for your help.

vincent
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.