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?
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?
Are there any benefits (from a programming perspective) of using one
convention over the other?
tnx
On Apr 25, 10:18 am, Frederick C. [email protected]
On 25 Apr 2008, at 17:48, RoRNoob wrote:
<%= 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
Without getting into the details, symbols use less memory.
On 25 Apr 2008, at 21:03, AndyV wrote:
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:
If it’s a name of something , or something that gets displayed to the
user, in most cases I’ll use strings.
Jason
Jason R. 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.
On 26 Apr 2008, at 00:07, Daniel W. wrote:
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs