ruby-on-railsrails-cells

How do you configure cells to work with a different url root?


My Rails 3.2 application runs under http://localhost/my-app. Without anything special, the image_url helper figures this out correctly:

<%= image_tag("test.png") %> #=> <img src="/my-app/assets/test.png" alt="Test">

However, when that same helper method is called from a cell, the url loses /my-app.

<%= image_tag("test.png") %> #=> <img src="/assets/test.png" alt="Test">

That of course results in a 404 response.

How to I properly configure cells to work with a different root url?

I've tried setting config.action_controller.relative_url_root = "/my-app", but that had no effect.

Here are the relevant bits needed to reproduce this:

# /app/cells/foo_cell.rb
class FooCell < Cell::Base  
  def test
    render
  end
end

# /app/cells/foo/test.html.erb
<%= image_tag("test.png") %>

# Somewhere in /app/views/layouts/application.html.erb
<%= image_tag("test.png") %>
<%= render_cell(:foo, :test) %>

Solution

  • One workaround is to include the full path in the image_tag call:

    <%= image_tag("/my-app/assets/test.png") %>