But we found that IE and Safari sends headers like:
HTTP_ACCEPT=>“text/html, /, text/javascript”, with the
javascript header last so this mucks up the respond_to block as it will
always enter the first block (usually format.html) and
never reach your format.js block.

We have a before filter called on required actions that forces the request
format to be
javascript if it is an xml_http_request?

Want something nicer looking (and currently, faster!) than using ERb for
your views? Have a look at haml (and it’s companion, sass, for
stylesheets). It will make you feel all fuzzy on the inside, I promise :P.

ERb example

haml equivalent

#profile.left.column#date= print_date#address= current_user.address

Shifting to haml from ERb feels strange at first, but after about 20
minutes it starts to feel nice. A little longer and you’ll really start
to notice your productivity (and of course, happiness) increase! :). I’ve
starting shifting all new
projects developed at our work office over to using haml (and sass), it’s
been fantastic!

Patch in yourself, or likewise you can use the following snippet (which is
the new link_to
method with modifications [there are also Array
extensions on edge to provide .second, .third etc which aren’t present]).

or better known as “throw on some more tasty meta-programming” :).
Given an example of a model which has a state (String) which must from a set of defined values,
e.g. pending, approved, denied.

class User<ActiveRecord::BaseSTATES=['pending','approved','denied']validates_inclusion_of:state,:in=>STATES# Define a named scope for each state in STATESSTATES.each{|s|named_scopes,:conditions=>{:state=>s}}end

This automatically defines a named_scope
for each of the model states without having to define a named_scope
manually for each state (nice and DRY).

In this example, we are editing a collection of region records, each with
its own select list of countries. (Region belongs_to :country.) If
the region doesn’t have a country associated, then we want a default
message of “unassigned”. Of course, if the region does have a country
associated then we want that country displayed: