Ruby on Rails

From DesigningPatterns

(Redirected from Ruby On Rails)
Jump to: navigation, search

Contents

General Info

Debugging + Testing

  • You can run the debugger by making a call to the method "debugger" where you want to set your breakpoint in the code, and by starting up the server with the -u option (ruby script/server -u).
  • The command (ruby script/console) allows you to bring up part of a Rails application in an irb session. This allows you to eg. call model methods and inspect the output.
  • Add calls to the debug method in the code (eg. debug(@order) ). This will print the order object in formatted html.
  • Use the logger. logger.info/warn/error/fatal/debug. You can specify the log level in the environment file.
  • Run only 1 test case method in a test case file w/ the following: ruby -I test test/unit/foo_test.rb -n test_a

Rake Tasks

  • You can "freeze" the Rails libraries that your app uses (or copy it into the vendor directory of your rails app), by running rake rails:freeze:gems
  • You can "freeze" the gems that your app uses by running rake gems:unpack.

Language

  • Rails has 3 permissioning modes: test, development, and production.
  • A Rails helper is a module of methods that are available (ONLY) to the view. When a helper is added in a controller, the associated helper file is required (& the module is included) in the view. A controller will by default add a helper w/ the same name prefix as the controller itself.
  • Calling content_for stores a block of markup in an identifier for later use. You can make subsequent calls to the stored content in other templates or the layout by passing the identifier as an argument to yield.

Additional Tools

  • Rad Rails is an IDE for Ruby On Rails
Personal tools