This project is archived and is in readonly mode.

#1015 ✓stale
Chris Hapgood

image_path helper won't generate absolute paths without asset_host

Reported by Chris Hapgood | September 10th, 2008 @ 10:35 PM | in 3.x

The image_tag and image_path helpers won't generate absolute paths unless ActionController::Base.asset_host is set.

The more fundamental cause is the ActionView::Helpers::AssetTagHelper#compute_public_path method and arguably the ActionView::Helpers::AssetTagHelper#compute_asset_host which returns an empty string when no asset_host is set.

This inability to return absolute paths without an asset host is particularly painful when using ActionMailer because HTML emails practically require the use of absolute paths.

I propose modifying compute_asset_host to return an appropriate asset host even if the AC::Base.asset_host is not set (where possible).

When asset_host is not set, we will rely on the ability of the root_url method to return a reasonable value. In many cases, this relies on the presence of default_url_options -including the ActionMailer case.

Comments and changes to this ticket

  • Chris Hapgood

    Chris Hapgood September 10th, 2008 @ 10:42 PM

    Attached patch to solve problem. Tests coming next...

  • Michael Koziarski

    Michael Koziarski September 11th, 2008 @ 03:55 PM

    • Assigned user set to “Pratik”
  • Pratik

    Pratik October 4th, 2008 @ 03:09 PM

    • State changed from “new” to “incomplete”

    Hey Chris,

    Patch doesn't apply anymore.

  • Chris Hapgood

    Chris Hapgood October 5th, 2008 @ 02:21 PM

    When I wrote this changeset up on the mailing list, nobody replied. No positive replies, no negative replies. So I'm led to believe that with ActionMailer people are either using an asset host or they have alternative workarounds to get linked images.

    In either case, the lack of interest has made me put my work into other issues for the time being. I'll try to get back to this ticket if you think it's worthwhile. Otherwise, let's close it. -Chris

  • Pratik

    Pratik October 5th, 2008 @ 02:28 PM

    • State changed from “incomplete” to “hold”

    Let's keep it on 'hold' for now and tackle it post 2.2 ( or till someone else faces the problem).

  • Jonathan del Strother

    Jonathan del Strother January 15th, 2009 @ 03:20 PM

    I for one would like to see this fixed. The attached patch is a little cleaner than the original and includes a test.

    Any thoughts on the use of root_url for computing this? Seems a little weird to be relying on something that may or may not be defined in routes, but I'm not sure there's a better way...

  • Pratik

    Pratik January 15th, 2009 @ 03:30 PM

    • Milestone cleared.
    • State changed from “hold” to “open”
  • Pratik
  • Pratik

    Pratik January 18th, 2009 @ 04:05 AM

    Umm, why can't we use default_url_options[:host] ?

  • Pratik

    Pratik January 28th, 2009 @ 07:56 PM

    • Milestone set to 2.x
  • Marko

    Marko January 29th, 2009 @ 07:34 PM

    I'm building newsletter now and this would be very useful feature.

  • Gregory Tomei

    Gregory Tomei February 11th, 2009 @ 07:11 PM

    +1 I would like to have absolute URLs possible in image_tag also

  • Ryan Sandridge

    Ryan Sandridge October 21st, 2009 @ 06:36 PM

    Specifying default_url_options[:host] in ActionMailer does not result in absolute image tags (or I'm doing something wrong).

  • gonzoyumo

    gonzoyumo April 13th, 2010 @ 11:49 PM

    Hi

    +1 too. Still stuck with html emails. would be intresting to have such a feature.

    what about it ?

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • masone

    masone July 16th, 2010 @ 04:45 PM

    • Importance changed from “” to “”

    Regarding Jonathan del Strothers patch.

    • The patch does not apply to master, but it does apply to 2-3-stable.
    • Tests do pass on 2-3-stable

    I personally think that the current behavior is perfectly fine. There is no asset host defined, so there is no absolute asset path. The behaviour only becomes obvious when you use the helper in mailer templates. The same problem applies to url_for too by the way.

    I don't like the idea of using the root_url as a fallback. It just doesn't feel right to me. And I don't think that it's a good idea to rely the implementation on route helpers.

    There are a few things I would reconsider:

    • Is there really the need for a change? Just setting the asset host would do the trick.
    • Find a generic solution that also fixes the url_for helper, not just the asset tag.
    • Think about an other solution than using root_url.
    • Return host instead of nil since that would match the behavior on line 577 (host would be nil in that case anyway)
  • Jarl Friis

    Jarl Friis August 27th, 2010 @ 03:48 PM

    I would like to see something like ActionView::Helpers::AssetTagHelper#image_url that returns the absolute url in stead of just the path as ActionView::Helpers::AssetTagHelper#image_path does.

    Jarl

  • Jarl Friis
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:49 PM

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:49 PM

    • State changed from “open” to “stale”
  • Greg Hazel

    Greg Hazel March 31st, 2011 @ 05:09 AM

    The wish for this to be fixed still exists. Using default_url_options[:host] seems like a reasonable answer.

    [state:open]

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages