1

I have a rails 3.1 application that uses a default layout with css in "/app/assets/stylesheets/application.css" as per standard practice. This works great with the asset pipelining stuff for the main part of my application.

But I use a different "reporting" layout when I generate a report that uses a /app/views/layouts/showreports.html.erb layout as follows:

<!DOCTYPE html>
<html>
<head>
  <%= stylesheet_link_tag "showreports" %>
  <%= javascript_include_tag "showreports" %>
  <%= csrf_meta_tag %>
</head>
<body>
  <div id="mainarea" class="container">
    <div class="span-24 last">
      <%= yield %>
    </div>
  </div>
</body>

I'm using rake assets:clean; rake assets:precompile to pre-compile my assets and check things are looking good in the manifest file (/public/assets/manifest.yml) and I don't see any references to showreports.css or showreports.js.

When I test my program in dev-mode, unsurprisingly, it can't locate those files.

I'm guessing this is a basic sprockets question with rails 3.1 but I thought sprockets would be smart enough to parse all the layout files for assets (beyond the default application.html.erb file).

Just wondering if this may be a bug or just my misunderstanding on how this should work.

Cheers,

Greg


UPDATE

After more tinkering, I'm answering my own question as this made the most sense for me...

This answer really gave the right clue

What I was doing wrong was using files named "showreports.css" and "showreports.js" as manifest files.

My fix was to create /app/assets/stylesheets/showreports and /app/assets/javascripts/showreports and then to rename my showreports.(css|js) to application.(css|js) inside their respective directories.

After doing so, rake assets:precompile found them nicely and added them correctly to the manifest file.

Community
  • 1
  • 1
Greg B
  • 551
  • 4
  • 10

2 Answers2

4

According to http://guides.rubyonrails.org/asset_pipeline.html you should also add following:

config.assets.precompile += %w(showreports.css showreports.js)

to your application.rb file

Lev Lukomsky
  • 6,346
  • 4
  • 34
  • 24
0

It's a misunderstanding. Rails Assets Pipeline only compiles files located in RAILS_ROOT/app/assets and you must reference them directly. If you want another file to be generated simply create another manifest file with similar content to application.css/js. Also check require directives to avoid including one file into the other.

Pablo Castellazzi
  • 4,164
  • 23
  • 20
  • @Pablo_Castellazzi. Thanks, but I'm a little lost on where/how to do this. Would I modify something in config/application.rb to force another manifest file to be generated or would I manually create this? – Greg B Sep 15 '11 at 17:25
  • 1
    A little bit of both. You need to create the files and add them to the array `config.assets.precompile` in `config/environments/production.rb`. – Pablo Castellazzi Sep 15 '11 at 17:53