Rails Views

(Part II)

Quick lecture overview

  • Asset Pipeline
  • Assets. Where to place?
  • Migration to HAML
  • Writing own helpers
  • Bootstrap integration

Asset Pipeline

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass and ERB.

Assets. Where to place?

Pipeline assets can be placed inside an application in one of three locations: app/assets, lib/assets or vendor/assets.


  • app/assets is for assets that are owned by the application, such as custom images, JavaScript files or stylesheets;
  • lib/assets is for your own libraries' code that doesn't really fit into the scope of the application or those libraries which are shared across applications;
  • vendor/assets is for assets that are owned by outside entities, such as code for JavaScript plugins and CSS frameworks.

Migration to HAML

Haml is a templating engine for HTML. It provides an elegant syntax that's both powerful and easy to understand. Rails installation:


gem 'haml'
					
gitHub repository

Writing own helpers

Using helpers we could place logic directly in the view.


Message

module ColorHelper def colored_class return 'red' if params[:error].present? 'green' end end

Bootstrap integration

Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web.

Rails Bootstrap Sass Gem
Q&A
No questions? No answers!

Created by Vasyl Lasiak / @vlasiak