This project is archived and is in readonly mode.

#2429 ✓stale
gummybears

Problem with relative_url_root (rails 2.2.2)

Reported by gummybears | April 6th, 2009 @ 12:08 PM | in 3.x

I am deploying 2 Rails apps on the same domain and address them as www.domain.com/app1 and www.domain.com/app2

Version info Rails 2.2.2, nginx 0.7.47 (ubuntu intrepid).

Problem description

I understood from the documentation I have to set config.action_controller.relative_url_root in config/environment.rb so the routing works.

But now the problem is that my stylesheets/javascript/images should be located in public/app1(app2) as all javascript_include_tag and stylesheet_link_tag prefixes the relative_url_root i.e


<link type="text/css" rel="stylesheet" media="screen" href="/app1/stylesheets/application.css?1238964891"/>

<script type="text/javascript" src="/app1/javascripts/swfobject.js?1238964891"/>

A quick and dirty fix is to put a symlink app1 in public to point to itself.

Everything worked fine with Rails < 2.2.2 where I didn't use relative_url_root.

Comments and changes to this ticket

  • Abdallah

    Abdallah May 13th, 2009 @ 01:42 PM

    • Tag set to relative_url_root

    Hello,

    Same problem,Has anyone got the solution for this problem??

    Thanks.

  • Marcel M. Cary

    Marcel M. Cary December 13th, 2009 @ 07:08 AM

    I've attached a patch for writing of concatenated JS and CSS assets with relative_url_root:

    When relative_url_root is in use, for example set to /foo, the :cache feature of javascript_include_tag breaks. Instead of writing the bundle to public/javascripts/all.js, the AssetTagHelper tries to write
    it to public/foo/javascripts/all.js. The stylesheet_link_tag has a similar problem.

    The problem seems to be that compute_public_path returns the path part of a URL to the resource, but the code assumes that is the same as it's path relative to public/.

    Strip the superfluous relative_url_root from the path before attempting to write to it.

    This patch was generated against rails 2.0.2. But 2.3.4 seems to have the problem (just from reading the code; I didn't actually run it). You can apply it with "git am" if you use Git, otherwise, I think patch -p1 should do the trick.

    .../lib/action_view/helpers/asset_tag_helper.rb | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)

  • Marcel M. Cary

    Marcel M. Cary December 14th, 2009 @ 06:57 AM

    Re-reading the ticket description, I realize my patch addresses a different problem that actually doesn't seem to exist in more recent rails 2.3.4. (This time by experimentation rather than trying to read the code.)

    It seems that static assets are served via a different code path than the one that relative_url_root affects. When I run rails with script/server --path=/foo, the static assets are served under /foo/stylesheets as you and the app expect. But if I just set relative_url_root in environment.rb they the static assets are not served from where the app expects them.

    Looking in commands/server.rb, it seems that when "--path" is not set, the server ignores relative_url_root, but when "--path" is set, the server sets relative_url_root to match. It uses the value of "--path" to setup a rack component for server static files. Perhaps when --path is not specified, server.rb should use the relative_url_root specified in environment.rb? (See attached patch for an example.)

    In any case, it seems you currently have to specifically tell whatever serves your static files (Apache or script/server) to mount public/ at a different URL path.

  • Marcel M. Cary

    Marcel M. Cary December 14th, 2009 @ 06:59 AM

    Hrm... seems the attached patch didn't go through. Here it is:

    From 74459162597c39d408d535fcd5f50b049220310c Mon Sep 17 00:00:00 2001
    From: Marcel Cary marcel@earth.care2.com
    Date: Sun, 13 Dec 2009 22:55:01 -0800
    Subject: [PATCH] Teach server command to use relative_url_root for static files


    vendor/rails/railties/lib/commands/server.rb | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)

    diff --git a/vendor/rails/railties/lib/commands/server.rb b/vendor/rails/railties/lib/commands/server.rb
    index ebe34a4..6cbbe27 100644
    --- a/vendor/rails/railties/lib/commands/server.rb +++ b/vendor/rails/railties/lib/commands/server.rb @@ -52,7 +52,6 @@ unless server end

    puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" -puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}#{options[:path]}"

    %w(cache pids sessions sockets).each do |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) @@ -86,12 +85,14 @@ else end

    if options[:path].nil? - map_path = "/" + map_path = ActionController::Base.relative_url_root || "/" else ActionController::Base.relative_url_root = options[:path] map_path = options[:path] end

    +puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}#{map_path}" + app = Rack::Builder.new { use Rails::Rack::LogTailer unless options[:detach] use Rails::Rack::Debugger if options[:debugger] -- 1.6.4.4

  • Marcel M. Cary
  • Jeremy Kemper

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

    • Milestone changed from 2.x to 3.x
  • Peter Pawlowski

    Peter Pawlowski May 6th, 2010 @ 10:34 PM

    Thanks for the patch, Marcel, it fixes the problem for me.

    I am seeing this problem on rails 2.3.4, to me it means that script/server is completely broken... Is there a reason this shouldn't go into the next stable 2.3.x of Rails?

    Since your patch was a little mangled, Marcel, I made up my own and will try to attach it.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 05:02 PM

    • State changed from “new” to “open”
    • Importance changed from “” to “”

    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 @ 05:02 PM

    • State changed from “open” to “stale”

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>

People watching this ticket

Attachments

Pages