Search code examples
javascriptruby-on-railsincludestylesheetassets

javascript_include_tag and stylesheet_link_tag


  1. I would like to know if there is some standard (Rails-version-independent) folder in Rails application where to put javascripts or stylesheets.
  2. when I insert javascript_include_tag and stylesheet_link_tag they link to /assets by default. How to specify folder, containing javascripts or folder containing stylesheets?
  3. I read that there is some Rails.application.config.assets.paths configuration thing which lets me to specify folder for assets (btw. in which .rb file should I assign its value?). But it seems to point out a single folder for all JS and CSS files together, but I want to store them in separate folders.

Solution

    1. For rails 3 you can put all your javascripts and CSS files in public/assets/javascripts and public/assets/stylesheets javascript_include_tag will be linked correctly in that case. For rails 2 the same, just leave assets out.
    2. those tags are helpers, so they point to the asset folder and respectively the folder /javascripts or /stylesheets.

      <%= javascript_include_tag "something" %>
      

      generates a link to /assets/javascripts/something.js

    3. You can edit the path in config/application.rb just place

      config.assets.enabled = true
      config.assets.paths << "#{Rails.root}/app/or_whatever_path_to_use"
      

      in there