Friday, February 17, 2012

Rails 3.2.1 with MongoDB quick checklist

I'm just writing this to remind myself of what I did to set up a baseline for Checkie, a checklist helper. Assumption: you have git installed, and you're a little familiar with RVM.

Install a gcc or configure RVM to use clang, and install Ruby 1.9.3

The OSX compiler set in XCode 4.2 changed out gcc for an LLVM based compiler. The corresponding compiler is called 'clang'. You may encounter issues installing Ruby 1.9.3 with RVM until fixes are made permanent; I figured out what to do in the meantime on StackExchange (please look it up there since YMMV).

I usually use an application-specific gemset. Assuming that 1.9.3 is current:

rvm gemset create checkie

I stick this sort of configuration into a local .rvmrc file in the working tree
echo "rvm use ruby-1.9.3-p0@checkie" > .rvmrc

The RVM install should have set up your .bash_profile or .bash_login so it will automatically read the .rvmrc when you cd to the directory. If not read up on it at the RVM home page.

Install mongodb

brew install mongo

Then follow instructions:

    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/Cellar/mongodb/2.0.2-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

Check out some references and tutorials

A few I looked through.

Fixup the Gemfile

I add a :production and :development group, things like the debugger and chose the server (thin, unicorn, whatnot...).  I also use Compass, Sass, HTML5 Boilerplate, Compass-Less, Fancy Buttons, Devise, Cancan, and a few other gems. Bundle, and check in to git and move on.

Initialize gems that need to be initialized

compass init rails .

vi app/views/layouts/application.html.haml   (add compass/sass stuff; round it out later)
  = stylesheet_link_tag 'screen.css', :media => 'screen, projection'
  = stylesheet_link_tag 'print.css', :media => 'print'
  /[if IE]
    = stylesheet_link_tag 'ie.css', :media => 'screen, projection'

vi config/application.rb (add block to opened Application class):
    config.generators do |g|
      g.template_engine :haml
      g.test_framework  :rspec
      g.orm             :mongoid

vi config/compass.rb  (add fancy-buttons)
  require "fancy-buttons"

vi app/assets/stylesheets/application.css.scss
@import "fancy-buttons";

rails generate mongoid:config
rails generate barista:install
rails generate rspec:install

vi spec/spec_helper.rb   (add rspec config with cucumber, comment out activerecord stuff)
  config.mock_with :rspec

  require 'database_cleaner'

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.orm = "mongoid"

  config.before(:each) do

rails generate cucumber:install --capybara --rspec --skip-database  

cat <<EOT > features/support/database_cleaner.rb
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid"
Before { DatabaseCleaner.clean }

rails generate devise:install

vi config/environments/development.rb:
   config.action_mailer.default_url_options = { :host => 'localhost:3000' }

vi config/routes.rb.
       root :to => "home#index"

vi app/views/layouts/application.html.haml

rails generate mongoid:devise User
vi routes.rb:
devise_for :users
rails generate cancan:ability

But wait...
rails g jquery:install --ui
 deprecated  You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.
              The necessary files are already in your asset pipeline.
              Just add `//= require jquery` and `//= require jquery_ujs` to your app/assets/javascripts/application.js
              If you upgraded your app from Rails 3.0 and still have jquery.js, rails.js, or jquery_ujs.js in your javascripts, be sure to remove them.
              If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.

(no need to edit the application.js -- the lines are already there)

(copy a bunch of view templates from another haml app for boilerplate)

rails g controller home index
rails g controller vip index

vi app/controllers/vip_controller.rb:
  before_filter :authenticate_user!

There's a lot more to do...

No comments: