Interesting Things
- Rails gotcha:
Date.parseandTime.parsedo not react the same when passed data that can’t be parsed:
<code>
$ script/console
Loading development environment.
>> Time.parse "monkey"
=> Thu Jun 14 08:43:10 PDT 2007
>> Date.parse "monkey"
ArgumentError: 3 elements of civil date are necessary
from /usr/local/lib/ruby/1.8/date.rb:650:in `new_with_hash'
from /usr/local/lib/ruby/1.8/date.rb:695:in `parse'
from (irb):2
>>
</code>- Rails gotcha #2: in functional tests,
assert_redirected_tocan fail if you are not consistent in your “strings vs symbols” notation. Example:
<code>
class MonkeyWranglersController < ActionController
def index
redirect_to :controller "monkey_wranglers", :action => :list
end
end
</code>Now, the assertions:
<code> get :index assert_redirected_to :controller => "monkey_wranglers", :action => :list # passes ### get :index assert_redirected_to :controller => "monkey_wranglers", :action => "list" # fails </code>
- More View helpers:
ActionView::Helpers::TextHelper::cyclehelps you with the “every-other-row-should-be-a-different-color” pattern usually seen in tabular data.