Add custom methods to Rails 3.1 asset pipeline?

后端 未结 2 2013
长发绾君心
长发绾君心 2020-12-17 20:07

How can I add my custom methods to my assets such as css files like Rails did with \'asset_path\' helper?

With Rail\'s own helper, I can write this:

         


        
2条回答
  •  甜味超标
    2020-12-17 20:34

    Normal helper methods are not available in asset views. To add you own methods you'll need to extend the Sprockets helper module. Have a look at the code of the built-in helpers to see how you might do this.

    In a nutshell you can add a file in lib with the same structure as this and add you own methods. Don't forget to include the new library in you application initializer.

提交回复
热议问题