small medium large xlarge

30 Oct 2008, 22:23
Giuseppe Caruso (22 posts)

I noticed that at page 139, while building the helper to create the div tag for the cart that the author uses strings for the “content_tag” helper parameters.

content_tag("div", attibutes, &block)

Just looking to Rails APIs I saw they use symbols instead.

content_tag(:div, attibutes, &block)

Is it just a different syntax or it should be better to use APIs way?

05 Nov 2008, 15:16
John Purnell (1 post)

There are trade-offs between the selection of a string or a symbol. Since you asked, permit me to run a bit off topic and suggest an “article”: by Josh Susser that I found helpful.

06 Nov 2008, 23:11
Giuseppe Caruso (22 posts)

John, really, really thanks a lot for the link. I started thinking no one cared about it. The article is really enlighten and the blog too is a mine! (a ruby mine, of course)

So, if I well understood, accordingly with his rules of thumbs:

bq. Conceptually, if it’s a name for something in code, it should be a symbol. If it’s domain data, it should be a string. If it’s both, it’s probably better to go with a symbol.

it should be right to use the symbol instead of the string, since I could use the div element several times in the project, right?

You must be logged in to comment