Wednesday, March 19, 2008

Rails irb or script/console tips in one glimpse

Summarize most basic tips of using script/console here:
  • # script/console (note: start it)
  • # script/console production (note: start it with production environment)
  • # script/console -s (note: run in sandbox, all change to data records will rollback)
  • >>$LOAD_PATH (note: see the load_path of current environment)
  • >>reload! (note: reload the environment)
  • >>clear
  • >>$ (note: use TAB key to see all environment variables)
  • >>Str (note: use TAB key to auto complete)
  • >>@hello = "Hello word!" (note: define variable)
  • >>@hello = Object.new (note: define variable)
  • >>@order = Order.find(1) (note: get an order object, order.rb should be in one of app models)
  • >>app.get "/articles/1234" (note: run controller by route path)
  • >>app.post "/login", {:login => "xiaobozz", :password => "12345"}
  • >>helper.image_tag "logo.gif" (note: run any method of actionview helpers)
  • >>y @order (note: YAML style output)

The best way to get familiar with these tips is to use them now :-)

1 comment:

tf said...

I did not know most of these options! Thanks for posting. Exactly what I was looking for.