Ruby on Rails - manifest files and directives in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails



Manifest Files and Directives in Ruby on Rails

In the assets initalizer (config/initializers/assets.rb) are a few files explicitly defined to be precompiled

# Precompile additional assets.
# application.coffee, application.scss, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

Example

Tthe application.coffee and application.scss are so called 'Manifest Files'. This files should be used to include other JavaScript or CSS assets. The following command are available:

  • require <path>: The require directive functions similar to Ruby's own require. It provides a way to declare a dependency on a file in your path and ensures it's only loaded once before the source file.
  • require_directory <path>: requires all the files inside a single directory. It's similar to path/* since it does not follow nested directories.
  • require_tree <path>: requires all the nested files in a directory. Its glob equivalent is path/**/*.
  • require_self causes the body of the current file to be inserted before any subsequent require directives. Useful in CSS files, where it's common for the index file to contain global styles that need to be defined before other dependencies are loaded.
  • stub <path>: remove a file from being included
  • depend_on <path>' Allows you to state a dependency on a file without including it. This is used for caching purposes. Any changes made to the dependency file will invalidate the cache of the source file

An application.scss file could look like:

/*
 *= require bootstrap
 *= require_directory .
 *= require_self
 */
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

Example

The application.coffee file. Here with including jquery and Turbolinks:

#= require jquery2
#= require jquery_ujs
#= require turbolinks
#= require_tree .
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

If you don't use CoffeeScript, but plain JavaScript, the syntax would be:

//= require jquery2
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

This ruby on rails tutorial page provides you the following key areas such as ruby , rail , ruby on rails , rail forum , ruby on rails tutorial , ruby tutorial , rails guides , rails tutorial , learn ruby , rails form_for , ruby rails , ruby class , what is ruby on rails , rails installer , ruby online , learn ruby on rails , ruby on rails jobs , rails find_by , install rails , easyrail , rubyonrails , link_to rails , ruby on rails developer , learn ruby the hard way , railscasts , ruby on rails examples , ruby on rails vs php , rails 4 , rails activerecord , rails generate , ruby and rails , ruby on rails download , install ruby on rails , ruby net http , what is rails , ruby app , ruby vs ruby on rails , ruby on rails windows , rails for zombies , ruby on rails book , ruby on rails development , ruby on rails ide , ruby on rails tutorial pdf

Related Searches to Manifest Files and Directives in Ruby on Rails