Noob ? - Diff Between "action => :index" and "action => 'index'" ?

What is the difference between specifiying a link_to action with a ":" vs. "''" ?

Example:

<%= link_to "Continue your spree", :action => :index %>

vs.

<%= link_to "Continue your spree", :action => 'index' %>

Is there one?

In one case you're passing the string 'index' and in the other case a symbol. rails doesn't care though.

Fred

Are there any benefits (from a programming perspective) of using one convention over the other?

tnx

Without getting into the details, symbols use less memory.

Without getting into the details, symbols use less memory.

On the other hand they can't be garbage collected. In practical terms,
I don't think it makes much difference either way.

Fred

But symbols never get GC'd. So use enough symbols, and you permanently use more memory.

My rule of thumb for symbol use: - hash keys - config specifications (has_many :my_things) - State designators (:open, :closed)

If it's a name of something , or something that gets displayed to the user, in most cases I'll use strings.

Jason

Jason Roelofs wrote:

But symbols never get GC'd. So use enough symbols, and you permanently use more memory.

My rule of thumb for symbol use: - hash keys - config specifications (has_many :my_things) - State designators (:open, :closed)

If it's a name of something , or something that gets displayed to the user, in most cases I'll use strings.

Jason

The memory argument is moot in Rails as it uses both.

See HashWithIndifferentAccess: http://api.rubyonrails.com/classes/HashWithIndifferentAccess.html

Rails' hashes use both.

Nearly nothing uses HashWithIndifferentAccess, (only the params hash I think). Deep down on the inside, it's a hash with string keys, but if you give it a symbol key it will convert that to a string first (and some other niceties related to that).

Fred