Don't forget about as

apalmblad Sep 3, 2010

:as is a good but poorly document argument to rendering a collection:

<%= render :partial => 'some_partial', :collection => an_array, :as => :better_name -%>

Which will give you each element of +an_array+ in the partial in a local variable named +better_name+ not +some_partial+.

Getting n..end in Rails

Mange Aug 17, 2010 1 thank

Nice one, henning. For anyone using Rails (ActiveSupport) a handy method called #from is also present.

[1, 2, 3, 4, 5].from(2) # => [3, 4, 5]

So our example would be

a.from(i)

It reads a lot better

Confusing log output

kratob Aug 13, 2010 1 thank

If you do a single Rails.cache.read('my_key'), your will usually see in your log something like

Cache read: my_key
Cache read: my_key
Cache write: my_key

Don't worry about this.

What happens here is this: Before going to memcached, rails will first ask a local MemoryStore...

When using enumerables

mrbongiolo Aug 9, 2010 2 thanks

When using enumerables and storing them as strings in the database don't forget to use .to_s or the select helper won't automatically select your choice when viewing your data after save.

Exemple:

dates = 1900..Date.today.year
f.select(:year, dates.collect {|d| [d.to_s,d.to_s]}, {:include_...

Testing Named Scopes

railsway-worker Aug 4, 2010 1 thank

Thanks for the example of testing named_scopes. Being new to Rails, I struggled to find examples that I could understand. Here is another "simple" test for a named_scope

Mine differs slightly from the one above in that I had to remove a set of {} in the :conditions in my test to avoid an "odd nu...