# When to use :symbol and when to use String?

**URL:** <https://www.ruby-forum.com/t/when-to-use-symbol-and-when-to-use-string/65673>\
**Category:** Ruby\
**Created:** [August 20, 2006, 1:09pm UTC](https://www.ruby-forum.com/t/when-to-use-symbol-and-when-to-use-string/65673 "2006-08-20T13:09:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 20, 2006, 1:09pm UTC](https://www.ruby-forum.com/t/when-to-use-symbol-and-when-to-use-string/65673/1 "2006-08-20T13:09:28Z")

</div>

Hi all

I experience that the use of symbols and strings is not consistent in  
Rails.

Very often I can use symbols as values in methods:

has\_and\_belongs\_to\_many :musician\_profiles,  
:join\_table =\> “musician\_profiles\_do\_show\_types”

# string

has\_and\_belongs\_to\_many :musician\_profiles,  
:join\_table =\> :musician\_profiles\_do\_show\_types

# symbol

But for example the link\_to helper does not allow me to use a symbol  
instead of a string:

link\_to “Test”, :controller =\> “news” # string

link\_to “Test”, :controller =\> :news # symbol

This second version using a symbol gives me this error:

undefined method `include?’ for :news:Symbol

Is there any reason for this? And if not, is there a way to achieve its  
functionality also with symbols, maybe using a plugin?

Thanks for infos,  
Joshua

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 20, 2006, 2:14pm UTC](https://www.ruby-forum.com/t/when-to-use-symbol-and-when-to-use-string/65673/2 "2006-08-20T14:14:10Z")

</div>

Dont know about rails, but use symbols whenever you dont  
need string behaviour (strnig behaviour like “foobar”[0,1] etc)

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 20, 2006, 3:42pm UTC](https://www.ruby-forum.com/t/when-to-use-symbol-and-when-to-use-string/65673/3 "2006-08-20T15:42:47Z")

</div>

There is really not a smart answer to this, at least as it pertains  
to Rails, besides that Rails is simply inconsistent on this matter in  
many cases. This is mostly for historical reasons.

However, here is a good explanation of Symbols in general. This is a  
common question, as you can probably imagine: [http://onestepback.org/](http://onestepback.org/)  
index.cgi/Tech/Ruby/SymbolsAreNotImmutableStrings.red

- Jake McArthur

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 21, 2006, 3:09am UTC](https://www.ruby-forum.com/t/when-to-use-symbol-and-when-to-use-string/65673/4 "2006-08-21T03:09:52Z")

</div>

> However, here is a good explanation of Symbols in general. This is a  
> common question, as you can probably imagine: [http://onestepback.org/](http://onestepback.org/)  
> index.cgi/Tech/Ruby/SymbolsAreNotImmutableStrings.red

Thank you for posting this. I’ve wondered about this many times, and  
this is the best explanation I’ve seen.
