Using Rails 3.1, where do you put your “page specific” JavaScript code?

前端 未结 29 2068
一生所求
一生所求 2020-11-22 11:08

To my understanding, all of your JavaScript gets merged into 1 file. Rails does this by default when it adds //= require_tree . to the bottom of your appl

29条回答
  •  自闭症患者
    2020-11-22 11:38

    The Asset Pipeline docs suggest how to do controller-specific JS:

    For example, if a ProjectsController is generated, there will be a new file at app/assets/javascripts/projects.js.coffee and another at app/assets/stylesheets/projects.css.scss. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as <%= javascript_include_tag params[:controller] %> or <%= stylesheet_link_tag params[:controller] %>.

    Link to: asset_pipeline

提交回复
热议问题