How to display controller specific javascript in rails 3.1?

前端 未结 5 811
我在风中等你
我在风中等你 2020-12-31 14:20

I have my assets folder structure like this

assets
  javascripts
    products
      --product.js
      --productValidate.js
    store
      --store.js
         


        
5条回答
  •  悲哀的现实
    2020-12-31 14:31

    This is what I am working on now to bridge the gap between Rails 3.1 assets pipeline and Jammit.

    I have not provided any documentation as it I consider it under development yet. But this is what it basically should allow you to do:

    # config/initializers/pakunok.rb
    # Define the dependencies between Rails assets:
    require 'pakunok'
    Pakunok::Pakunok.current.configure do
      asset('products/product.js').needs('products/productValidate.js')
    end
    

    And then, in your layout, you only need to do a single include. All the dependent files will be included automatically:

    # app/views/layouts/application.html.erb
    <%= include_javascripts %>
    

    Please see the specs to learn what the gem can do. Note: it is still under development and the gem itself will be split into multiple ones later.

    For any particular use-cases that you want to be supported, please submit issues and I promise to work hard to implement those when I'll have time :)

提交回复
热议问题