0

Is there a way to use the rails asset pipeline outside of erg? When I call stylesheet_link_tag(), I get a normal /stylesheets/ link instead of an /assets/ like I'd expect. I suspect that the stache gem just needs to register something with the asset pipeline, but I'm not sure what.

I'm using this gem: https://github.com/agoragames/stache

The code I'm using:

module Layouts                                              
  class Application < ::Stache::View                        

  include ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers                                                   

    def title                                               
      'foobar'                                              
    end                                                     

    def stylesheets                                         
      [                                                     
        [stylesheet_link_tag('reset', :media => 'all')]     
      ]                                                     
    end                                                     

    def javascripts                                         
    end                                                     
  end                                                       
end                                                         

It's generating:

<link href="/stylesheets/reset.css" media="all" rel="stylesheet" type="text/css" />

It should be generating (it does this in erb templates):

<link href="/assets/reset.css?body=1" media="all" rel="stylesheet" type="text/css" />

Using rails 3.2.3.

zombor
  • 3,247
  • 17
  • 30
  • Which ror version are you using? What is the complete link you are getting to the stylesheet? And what do you have in you application.js – Sully May 14 '12 at 17:45

2 Answers2

1

Try

def stylesheets                                         
   [                                                     
     [stylesheet_link_tag("#{ActionController::Base.helpers.asset_path('reset.css')}", :media => 'all')] 
   ]                                                     
end 

also read https://stackoverflow.com/a/9341764/643500

Community
  • 1
  • 1
Sully
  • 14,672
  • 5
  • 54
  • 79
  • This worked. Is there a way to set this "globally" so that I don't have to do `ActionController::Base.helpers.asset_path()` every time? – zombor May 14 '12 at 23:08
  • define an initialize function and set it there then use it. Don't forget to mark the question as accepted. – Sully May 15 '12 at 15:12
  • See my answer. This lets me use the rails helpers "normally". – zombor May 15 '12 at 18:42
1

The proper solution is to remove the:

include ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers

line at the top.

zombor
  • 3,247
  • 17
  • 30
  • If he removes that then he won't be able to use stylesheet_link_tag, no? – Sully May 15 '12 at 18:45
  • I originally thought that as well, but it works. I answered my own question, btw :) – zombor May 15 '12 at 18:47
  • Check it as accepted (Green check mark) Glad to know you got it sorted. You may want to accept all your previous questions to get more answers from the community in the future. – Sully May 15 '12 at 19:04
  • Not every question I've asked has gotten a sufficient answer. It won't let me accept my own answer until tomorrow. – zombor May 15 '12 at 19:36