Warbler and rails3, public files broken?

Hey Folks,

I’ve been playing with Rails3 (3.0.0.beta4) and warbler… deploying to
WebSphere 7. I’ve managed to get my app ported over to rails3 and
packaged into a .war file… it even deploys to WebSphere fine, starts,
and appears to run great! However… assets do not get served properly.

I’m using:
rails 3.0.0.beta4
jruby-rack 1.0.1
warbler 1.1.0
jruby 1.5.0

To boil it down, this is easily reproducible with a bare bones rails3
app and warbler. No need to add any controllers or generate anything.
Simply create a new app, warbler it*, and deploy to WebSphere with a
context root of anything except /. Browsing to the app’s root, which
should render public/index.html, fails with:

ActionController::RoutingError (No route matches “/”)

The same procedure works fine with Rails 2.3.8.

I suspect the context root I am deploying to in WebSphere is not mapping
correctly with rails3. Public stuff should be served before routing even
gets involved right?

Also, image_tag (and friends) do not generate a URL with the context
root prefixed, which I am guessing is bad, but a good clue :slight_smile: What I am
guessing should be populated with the prefix,
controller.config.relative_url_root, is empty, but
ENV[“RAILS_RELATIVE_URL_ROOT”] does have the prefix in it. Seems like a
mismatch to me… however, I’m a bit confused by the rails3 changes with
respect to relative_url_root, so I’m not sure what is correct anymore…
What I can say is that compute_public_path in actionpack’s
asset_tag_helper.rb uses controller.config.relative_url_root vs
ENV[“RAILS_RELATIVE_URL_ROOT”] so it is not surprising image_tag is
wrong. I can fix compute_public_path, but the routing issue still
remains, so I suspect there is a deeper root cause here.

Anyone have ideas?

  • Note: I am using a custom web.xml as WebSphere doesn’t like the
    default one generated by warble. Can post if necessary.

Thanks!

  • nick

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Fri, Jun 11, 2010 at 8:00 PM, Nicholas J Kreucher [email protected]
wrote:

warbler 1.1.0
jruby 1.5.0

To boil it down, this is easily reproducible with a bare bones rails3
app and warbler. No need to add any controllers or generate anything.
Simply create a new app, warbler it*, and deploy to WebSphere with a
context root of anything except /. Browsing to the app’s root, which
should render public/index.html, fails with:

ActionController::RoutingError (No route matches “/”)

I noticed recently that in Rails 3, there is a new
“config.serve_static_assets” option that defaults to false in the
production environment. You can change this as a short-term fix, but
I’d suggest looking into how to ensure that your assets get served by
either Websphere or a front-end web server.

Are you using the RackFilter in web.xml? This should make Websphere
serve the assets, but it’s possible something doesn’t work quite right
there.

respect to relative_url_root, so I’m not sure what is correct anymore…
What I can say is that compute_public_path in actionpack’s
asset_tag_helper.rb uses controller.config.relative_url_root vs
ENV[“RAILS_RELATIVE_URL_ROOT”] so it is not surprising image_tag is
wrong. I can fix compute_public_path, but the routing issue still
remains, so I suspect there is a deeper root cause here.

I haven’t completely sorted out the relative_url_root issues with
Rails 3 – it looks like the option is going to be deprecated – but
JRuby-Rack should attempt to set both values for you. See

/Nick

Anyone have ideas?

  • Note: I am using a custom web.xml as WebSphere doesn’t like the
    default one generated by warble. Can post if necessary.

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Mon, 2010-06-14 at 11:27 -0500, Nick S. wrote:

I noticed recently that in Rails 3, there is a new
“config.serve_static_assets” option that defaults to false in the
production environment. You can change this as a short-term fix, but
I’d suggest looking into how to ensure that your assets get served by
either Websphere or a front-end web server.

Wow… I totally missed that new option, how embarrassing!

Are you using the RackFilter in web.xml? This should make Websphere
serve the assets, but it’s possible something doesn’t work quite right
there.

Here is what I am using (web.xml.erb):

<% webxml.context_params.each do |k,v| %> <%= k %> <%= v %> <% end %> <%= webxml.servlet_context_listener %> Rails org.jruby.rack.RackServlet Rails /* <% if webxml.jndi then webxml.jndi.each do |jndi| %> <%= jndi %> javax.sql.DataSource Container <% end; end %>

wrong. I can fix compute_public_path, but the routing issue still
remains, so I suspect there is a deeper root cause here.

I haven’t completely sorted out the relative_url_root issues with
Rails 3 – it looks like the option is going to be deprecated – but
JRuby-Rack should attempt to set both values for you. See

jruby-rack/src/main/ruby/jruby/rack/rails/railtie.rb at master · nicksieger/jruby-rack · GitHub

Hmm, interesting. Perhaps controller.config.relative_url_root (as used
in actionpack) is getting clobbered somehow? After turning on
config.serve_static_assets, I still need the following patch in order
for assets to be linked to correctly (patch for compute_public_path):

— actionpack-3.0.0.beta4/lib/action_view/helpers/asset_tag_helper.rb
2010-06-14 12:51:34.310991243 -0700
+++
actionpack-3.0.0.beta4/lib/action_view/helpers/asset_tag_helper.rb-nick
2010-06-14 12:50:59.498991171 -0700
@@ -748,8 +748,8 @@
source = rewrite_asset_path(source, config.asset_path)

       has_request = controller.respond_to?(:request)
  •      if has_request && include_host && source !~ 
    

%r{^#{controller.config.relative_url_root}/}

  •        source = "#{controller.config.relative_url_root}#{source}"
    
  •      if has_request && include_host && source !~ 
    

%r{^#{ENV[“RAILS_RELATIVE_URL_ROOT”]}/}

  •        source = "#{ENV["RAILS_RELATIVE_URL_ROOT"]}#{source}"
         end
         source = rewrite_host_and_protocol(source, has_request) if 
    

include_host

It is probably worth noting that link_to works fine out of the box…
aka it does prefix the relative root properly in links. So whatever
url_for is doing seems correct.

Thanks!

  • nick (kreucher)

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Sun, 2010-06-27 at 21:11 -0700, dudzjosh wrote:

Have you tried putting this in your config/application.rb file or
environment file?
config.action_controller.relative_url_root = ‘/your_app’

No I have not… JRuby seemed to be doing something similar under the
covers. When I have the chance, I’ll try setting it explicitly and will
report back.
- nick