Architecting a Rails 3.1 App
$ gem install rails [--pre] $ rails new bug -d postgresql
Options to consider:
Ruby Toolbox is a good place to look for common rails plugins and gems to add functionality for your project. Here are the ones I like to consider.
Rails Wizard is a cool tool to generate a rails template, automatically installing the tools you select. When you are done, just run the
rails command it gives you.
rails new APP_NAME -m http://railswizard.org/5af13000c1b677a4453a.rb
If you want to apply this template to an existing application, you can do:
rake rails:template http://railswizard.org/5af13000c1b677a4453a.rb
Rubygems is the starting point to search for these gems. I have copied many gem descriptions into this page directly from their rubygems page.
IRB & Environment
These gems are useful in your RVM
global namespace, which is shared across projects. Of course, you can add them directly to your
Gemfile and have them available for everyone.
irb extension to pretty print Ruby objects to visualize their structure.
Wirble: is a set of enhancements for
irb, including tab-completion, history, and a built-in ri command, as well as colorized results and a couple other goodies.
Hirb: improves output for inspect output.
Nifty Generators: is Ryan Bate’s collection of generators for layouts and scaffolding.
group :development do gem 'awesome_print' gem 'wirble' gem 'hirb' gem 'ruby-debug19' gem 'nifty-generators' end
irbrc or ~/.irbrc:
require 'rubygems' require 'wirble' require 'awesome_print' # start wirble (with color) Wirble.init Wirble.colorize
Formtastic: Rails form builder plugin/gem with semantically rich and accessible markup. Also install the validation_reflection gem to build in your required validations into the form. A good getting started document is on the github page.
gem "formtastic" gem "validation_reflection"
rails generate formtastic:install
This generates the configuration file at
Add the stylesheet to the head section of
<%= stylesheet_link_tag 'formtastic', 'formtastic_changes' %>
Generate forms for the model, overwrites app/views//_form.html. rails generate formtastic:form Post –haml
Simple Navigation: A ruby gem for creating navigations (with multiple levels) for your Rails2, Rails3, Sinatra or Padrino applications. Render your navigation as html list, link list or breadcrumbs. See the examples for demonstrations and stylsheets.
Layouts and Assets
Follow the setup instructions at the github page.
Compass: a Sass-based Stylesheet Framework that streamlines the creation and maintainance of CSS.
compass init rails /path/to/railsroot
CSS3 Buttons: Rails helper methods and generators for the css3buttons by Michael Henriksen. This is a clean, github-like button look.
rails c css3buttons
Add the stylesheet to the layout file:
<%= css3buttons_stylesheets %>
<%= button_link_to "Search", search_path %>
Nifty Generators Layout
Nifty Generators Layout Installation:
rails g nifty:layout --help
Authentication and Authorization
Devise: Flexible authentication solution for Rails with Warden
Generate and devise engine, and edit the files to enable specific features, and finally migrate the database. See the devise github page for more information.
rails generate devise:install rails generate devise User edit app/models/user.rb db/migrate/*devise_create_users* rake db:migrate
Add to config/routes.tb
Onmuauth: an authentication framework that that separates the concept of authentiation from the concept of identity, providing simple hooks for any application to have one or multiple authentication providers for a user. See more at the omniauth homepage.
rails g cancan:ability
Active Record Extensions
rails g kaminari:config
Pagination control in the View:
<%= paginate @users, :window => 2 %>
Sunspot: Sunspot is a library providing a powerful, all-ruby API for the Solr search engine. Sunspot manages the configuration of persistent Ruby classes for search and indexing and exposes Solr’s most powerful features through a collection of DSLs. Complex search operations can be performed without hand-writing any boolean queries or building Solr parameters by hand. Instructions on github.
ZenTest: ZenTest provides 4 different tools: zentest, unit_diff, autotest, and multiruby. ZenTest scans your target and unit-test code and writes your missing code based on simple naming rules, enabling XP at a much quicker pace. ZenTest only works with Ruby and Test::Unit. Nobody uses this tool anymore but it is the package namesake, so it stays. unit_diff is a command-line filter to diff expected results from actual results and allow you to quickly see exactly what is wrong. autotest is a continous testing facility meant to be used during development. As soon as you save a file, autotest will run the corresponding dependent tests. multiruby runs anything you want on multiple versions of ruby. Great for compatibility checking! Use multiruby_setup to manage your installed versions.
Install your testing tools
group :test, :development do gem 'turn', :require=>false gem "rspec-rails" #, "~> 2.4" gem "webrat" gem 'cucumber-rails' gem 'database_cleaner' gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i gem 'guard-rspec' gem 'guard-livereload' gem 'guard-cucumber' end
rails generate rspec:install rails generate cucumber:install guard init rspec guard init cucumber guard init livereload vim Guardfile guard