Ruby on Rails

RoR on NetBeans

Before Nov 2007

Sessions

CSV support

Accepting XML or YAML

Receiving email in Rails

Transforming models to XML

Use to_xml. Options are:

  • :except: exclude these attributes
  • :include: include the specified models
  • :dasherize: if true, convert use dashes for spaces

file_column plugin

  • The plugin also adds methods to help with unit tests. Refer to the file file_column/lib/test_case.rb
    • setup_fixture_files
    • teardown_fixture_files

Caching

Tagging

Deployment using clusters

Handling missing actions and other exceptions

Override the method method_missing(methodname, *args) to handle missing actions (i.e. error 404)

  def method_missing(methodname, *args)
    @methodname = methodname
    @args = args
    render :action => "404", :status => 404
  end

More info at:

Doing something before an action

  • Use before_filter :some_method to do something before an action, such as requiring authentication.
  • Use skip_before_filter :some_method if you want a subclass to skip it's parent class's before_filters.

Authentication

Install on Mac OS X

Use DarwinPorts (renamed MacPorts), which will install necessary software in /opt. (details)

  • Also refer to the addendum
  • Requires setting socket /opt/local/var/run/mysql5/mysqld.sock in database.yml.

Speed up CSV parsing in Ruby on Rails

The CSV::Reader class in Ruby is slow at parsing CSV files. Use FasterCSV (details).

Prevent logging of form data

Use filter_parameter_logging "name_of_parameter". (details).

Variables

Protocol, host, and port of request
request.protocol + request.host_with_port
Session id
session.session_id

Miscellaneous