Rails asset_ids with Warbler

I was having a problem getting my rails_asset_ids working when
deploying as a WAR using warbler 0.9.11. I was able to get as far as
getting Rails not to assume RAILS_ROOT/public in
ActionView::Helpers::AssetTagHelper#rails_asset_id by setting
Rails.public_path = “#{RAILS_ROOT}/…”. This still only got me so far
since the source being passed to #rails_asset_id includes the
relative_url_root and so would look for a file like ‘WEB-INF/…/MyApp/
javascripts/x.js’ when attempting to grab the file modification time.
If I changed my warble.rb to make sure the assets did get put into a
subdir named for my app, then the asset_ids worked OK, but then the
browser wouldn’t locate as ‘/MyApp/javascript/x.js’ anymore(instead
at /MyApp/MyApp/javascript/x.js). In order to get this working I wound
up with the following monkey patch to AassetTagHelper to account for
the relative_url_root.

module ActionView
module Helpers
module AssetTagHelper
alias :old_rails_asset_id :rails_asset_id

   def rails_asset_id(source)
     source = source.sub(/

^#{ActionController::AbstractRequest.relative_url_root}/, ‘’)

     old_rails_asset_id(source)
   end
 end

end
end

I have a high suspicion that I’ve gone down the wrong path. Can anyone
offer a better alternative?

Thanks,
-lenny


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Tue, Sep 16, 2008 at 4:01 PM, Lenny M. [email protected] wrote:

‘/MyApp/javascript/x.js’ anymore(instead at /MyApp/MyApp/javascript/x.js).
source.sub(/^#{ActionController::AbstractRequest.relative_url_root}/, ‘’)

   old_rails_asset_id(source)
 end

end
end
end

I have a high suspicion that I’ve gone down the wrong path. Can anyone offer
a better alternative?

Warbler/JRuby-Rack is supposed to set Rails.public_path to the root of
the war file by default. Is that not working for you? What’s the set
value of Rails.public_path after the environment is loaded but without
any of your monkey patching?

/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Sep 16, 2008, at 10:25 PM, Nick S. wrote:

relative_url_root
patch to
^#{ActionController::AbstractRequest.relative_url_root}/, ‘’)

Warbler/JRuby-Rack is supposed to set Rails.public_path to the root of
the war file by default. Is that not working for you? What’s the set
value of Rails.public_path after the environment is loaded but without
any of your monkey patching?

/Nick

Hi Nick,

You are right. Rails.public_path is being set to the root of the war
correctly so that is not part of the problem, but there is still a
problem that when AssetTagHelper#rails_asset_id(source) is called, the
source includes the relative_url_root.

For example, assuming the root of my war is at /pathtowar and my
application is deployed at /MyApp. javascript_include_tag(‘myapp’ )
would result in rails_asset_id being called with /MyApp/javascripts/
myapp.js. That is the correct src path to be output but rails_asset_id
ends up attempting to read the modification time of the non-existent /
pathtowar/MyApp/javascripts/myapp.js. When I monkey patch
rails_asset_id to strip the relative_url_root(/MyApp) it does find the
file and append the mod time.

-lenny


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Wed, Sep 17, 2008 at 11:04 AM, Lenny M. [email protected] wrote:

correct src path to be output but rails_asset_id ends up attempting to read
the modification time of the non-existent
/pathtowar/MyApp/javascripts/myapp.js. When I monkey patch rails_asset_id
to strip the relative_url_root(/MyApp) it does find the file and append the
mod time.

That’s good to know. I take it you’re using Rails 2.1? There could be
new logic that I missed or haven’t accounted for regarding
relative_url_root. I’ll try to investigate and make sure JRuby-Rack
accounts for it.

/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Sep 17, 2008, at 1:40 PM, Nick S. wrote:

application
append the
mod time.

That’s good to know. I take it you’re using Rails 2.1? There could be
new logic that I missed or haven’t accounted for regarding
relative_url_root. I’ll try to investigate and make sure JRuby-Rack
accounts for it.

Yes. Forgot to specify that I am on Rails 2.1. I was pretty much
leaning toward this being an issue with AssetTagHelper when used with
a relative_url_root. Also, I had to move all my assets into public/
MyApp just for development once I set the relative_url_root because
the AssetTagHelper was outputing paths like /MyApp/javascript/x.js and
that would result in ‘no route’ errors in WEBrick. Now I’m thinking I
shouldn’t have had to do that.

Could be related to:
http://rails.lighthouseapp.com/projects/8994/tickets/1022-asset-caching-does-not-work-with-relative_url_root

Thanks,
-lenny


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email