Yesterday I was at the MountainRB ruby workshop, which was basically an intro to rails class. It was a really good workshop and here are some tips I picked up.

Cucumber

Change the config/cucumber.yml file to display pretty output, making it easier to see the failed step.

default: -format pretty

use Background: in cucumber features for tasks that need to happen for every scenario. Use just like Scenario

Background: Make sure that we have a topic
  Given I go to the topics page
  And I follow "New Topic"
  And I fill in "Title" with "Rails Fixtures" 
  And I fill in "Description" with "Introduce how to add test data with fixtures."
  And I press "Create"

Rails templates

When you create a new rails application you can specify a template that runs after the initial generation. It can handle a lot of the initial setup. Here’s the one used used in the workshop http://gist.github.com/609269.txt

rails new APP_NAME -m TEMPLATE_URL

View a models attributes

From inside the rails console you can view a models attributes by calling class on an instance of the Model.

ruby-1.9.2-p0 > (User.new).class

Routes

rake routes will show the routes defined for the application.

        login        /login(.:format)          {:action=>"new", :controller=>"user_sessions"}
         logout        /logout(.:format)         {:action=>"destroy", :controller=>"user_sessions"}
user_sessions GET    /user_sessions(.:format)  {:action=>"index", :controller=>"user_sessions"
user_sessions POST   /user_sessions(.:format)  {:action=>"create", :controller=>"user_sessions"}

Notes

Rails will cascade saves in a transaction by default

The resource generation option will create the model and migration, while adding a blank controller and empty views directory.

rails generate resource

heroku open shows the current heroku app in the browser.

Resources

http://bit.ly/ruby-resources – Resources from DevChix

http://railsapi.com – Rails documentation

http://boulderruby.org – Boulder user group

http://groups.google.com/group/derailed – Denver user group

http://RailsBridge.org - an inclusive and friendly Ruby on Rails community