Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3431340
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:18:50+00:00 2026-05-18T07:18:50+00:00

Sorry in advance for the question length, but I wanted to summarize my knowledge

  • 0

Sorry in advance for the question length, but I wanted to summarize my knowledge up to this point and try to hone in on the right solution quicker.

I have an application that will sometimes be embedded on another web page. To simplify the explanation, imagine a single server, that serves up either a normal app or a version of the app for embedding, depending on the domain name.

For the latter domain, links that the app generates with link_to, product_url, image_tag, etc., should be absolute (http://servername/images/image_01.jpg), and for the former, they should be relative (I think, unless I can’t solve this problem elegantly).

I know I can generate absolute URLs using, for example, product_url(:id, [...], :host => request.host, :port => request.port), but I see two problems with this approach. Firstly, it seems inefficient to rewrite this code in every link request in every view. Secondly, when the application is running on its own, not embedded, I would rather have relative URLs for efficiency and best practices.

For static assets, it’s possible to do the following, in config/environments/whatever.rb:
config.action_controller.asset_host = "http://assets.example.com"

But, this does not affect links generated by Rails.

I’ve been searching for an answer for this for a couple of days, and have nothing current for Rails 3. There is an old bit of code here that does the trick for Rails 2:

http://opensoul.org/2009/2/21/force-absolute-urls

But it doesn’t seem to work for Rails 3. So…

  1. Should I make some helper function that detects if the links are going to be embedded?
  2. Patch url_for to make it work how I want, without application view changes?
  3. Rewrite all my view files anyway?

Thanks in advance to any replies.

Cheers,

Zev

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:18:51+00:00Added an answer on May 18, 2026 at 7:18 am

    I’ve hunted through the sources and it seems Rails 3.0 don’t support setting that as a default. I’d probably go for monkey-patching url_for unless you have a really good reason not to.

    There is an option :only_path that if you either set to default true or default something based on the domain. Currently it defaults to the presence of the :host option. This patch could possibly break some not so well coded plugins, make sure you test them well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry in advance as this question is similar (but not the same!) to others.
Sorry if this is a question with a obvious answer but my knowledge with
Sorry in advance for this incredibly simple question, but what is the best way
Sorry in advance everyone for this question as I know the cascading select boxes
Sorry in advance for this being such a beginner question. Here are the steps
In advance: sorry for the noob question but I'm learning Cocoa & Objective-C and
Sorry if this is too simple, but thanks in advance for helping. This is
Sorry for this simple question, but I can't solve it... There is an example:
Sorry, I know this question is easy, but I don't know how to get
I'm sorry in advance if this question is flawed. I'm pretty new to databases(I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.