#329 More on Twitter Bootstrap pro
This episode continues on the Twitter Bootstrap project showing how to display flash messages, add form validations with SimpleForm, customize layout with variables, and switch to using Sass.
- Download:
- source codeProject Files in Zip (167 KB)
- mp4Full Size H.264 Video (35.7 MB)
- m4vSmaller H.264 Video (17.3 MB)
- webmFull Size VP8 Video (16.9 MB)
- ogvFull Size Theora Video (44.3 MB)
Resources
- Episode 328: Twitter Bootstrap Basics
- Twitter Bootstrap
- SimpleForm 2.0 + Bootstrap
- variables.less
- Too LESS? Should You Be Using Sass?
- bootstrap-sass
layouts/application.html.erb
<% flash.each do |name, msg| %> <div class="alert alert-<%= name == :notice ? "success" : "error" %>"> <a class="close" data-dismiss="alert">×</a> <%= msg %> </div> <% end %>
Gemfile
gem 'simple_form'
terminal
rails g simple_form:install --bootstrap
products/_form.html.erb
<%= simple_form_for @product, :html => { :class => 'form-horizontal' } do |f| %> <fieldset> <legend><%= controller.action_name.capitalize %> Product</legend> <%= f.input :name %> <%= f.input :price %> <div class="form-actions"> <%= f.submit nil, :class => 'btn btn-primary' %> <%= link_to 'Cancel', products_path, :class => 'btn' %> </div> </fieldset> <% end %>
app/assets/stylesheets/bootstrap_and_overrides.css.less
// CSS Reset @import "reset.less"; // Core variables and mixins @import "variables.less"; // Modify this for custom colors, font-sizes, etc @import "mixins.less"; // Grid system and page structure @import "scaffolding.less"; @import "grid.less"; @import "layouts.less"; // Base CSS @import "type.less"; @import "code.less"; @import "forms.less"; @import "tables.less"; // Components: common @import "sprites.less"; @import "dropdowns.less"; @import "wells.less"; @import "component-animations.less"; @import "close.less"; // Components: Buttons & Alerts @import "buttons.less"; @import "button-groups.less"; @import "alerts.less"; // Note: alerts share common CSS with buttons and thus have styles in buttons.less // Components: Nav @import "navs.less"; @import "navbar.less"; @import "breadcrumbs.less"; @import "pagination.less"; @import "pager.less"; // Components: Popovers @import "modals.less"; @import "tooltip.less"; @import "popovers.less"; // Components: Misc @import "thumbnails.less"; @import "labels.less"; @import "progress-bars.less"; @import "accordion.less"; @import "carousel.less"; @import "hero-unit.less"; // Utility classes @import "utilities.less"; // Has to be last to override when necessary body { padding-top: 60px; } @import "twitter/bootstrap/responsive"; // Set the correct sprite paths @iconSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings.png'); @iconWhiteSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings-white.png'); @navbarBackground: #555; @navbarBackgroundHighlight: #888; @navbarText: #eee; @navbarLinkColor: #eee; .navbar .brand { color: #FAFFB8; }
app/assets/javascripts/application.js
//= require twitter/bootstrap/bootstrap-transition //= require twitter/bootstrap/bootstrap-alert //= require twitter/bootstrap/bootstrap-modal //= require twitter/bootstrap/bootstrap-dropdown //= require twitter/bootstrap/bootstrap-scrollspy //= require twitter/bootstrap/bootstrap-tab //= require twitter/bootstrap/bootstrap-tooltip //= require twitter/bootstrap/bootstrap-popover //= require twitter/bootstrap/bootstrap-button //= require twitter/bootstrap/bootstrap-collapse //= require twitter/bootstrap/bootstrap-carousel //= require twitter/bootstrap/bootstrap-typeahead
Sass Variation
Update 3/29/12: It is important to rename the local bootstrap.js.coffee file so it does not interfere with the loading of bootstrap-sass file of the same name. Here is the Terminal command to do this.
terminal
mv app/assets/javascripts/bootstrap.js.coffee app/assets/javascripts/bootstrap_additions.js.coffee
Gemfile
group :assets do gem 'bootstrap-sass' end
app/assets/stylesheets/bootstrap_and_overrides.css.scss
// Set the correct sprite paths $iconSpritePath: image-path('glyphicons-halflings.png'); $iconWhiteSpritePath: image-path('glyphicons-halflings-white.png'); $navbarBackground: #555; $navbarBackgroundHighlight: #888; $navbarText: #eee; $navbarLinkColor: #eee; @import "bootstrap"; body { padding-top: 60px; } @import "bootstrap-responsive"; .navbar .brand { color: #FAFFB8; }
app/assets/javascripts/application.js
//= require bootstrap