Rails have a nice template engine called erb and it's cool however haml is super cool and in this class we practiced using haml along with bootstrap while understanding partials and helpers.
3. Agenda
Views, partials and helpers
rendering and layout
adding haml and syntax difference
compared to ERB
adding twitter bootstrap and
responsive grid design basics
4. Views, partials and
helpers
Views are loaded by
convention.
Normal content will fall
in main yield part.
_ prefixed files are
called partials and are
rendered inside views
for reusability sake.
Example: _form in any
scaffold.
10. Installation and
Usage
add following gems to your Gemfile and bundle
gem 'twitter-bootstrap-rails'
gem 'haml'
gem ‘haml-rails'
now install bootstrap static assets
rails generate bootstrap:install static
Generate fluid layout
rails g bootstrap:layout application fluid*
Scaffold and style
rails g bootstrap:themed <scaffold_model>s
*remove the .erb default one
11. Add new regions to
layout
-if content_for?
= yield
= yield(:region)
= content_for do
12. Associated Model
form best practices
Use
”accepts_nested_att
ributes_for” to
accept data from
associated model.
Use
“fields_for” to show
this associated
model fields.
Use
”validated_associate
d” to validate related
model
Use
form builder’s
collection_* to link
related models
Example:
collection_select