Topic: "Variable" symbol names?

This is actually more like a Ruby question, but this forum is just so darned helpful smile

Is there a way to make a symbol's name variable? For example, I have a list of comments and each comment's div tag has an id like "comment_<rowID>" where <rowID> is the numeric ID in the comments table.

Inside a .rjs file, how would I reference that ID? page[:comment_@comment], something like that? Or is page["comment_#{@comment}"] completely valid?


Re: "Variable" symbol names?

page["comment_#{@comment}"] should work so long as you set the @comment instance variable.

If art interprets our dreams, the computer executes them in the guise of programs.

-SICP (Abelson, Sussman)

Re: "Variable" symbol names?

Yeah, usually in rails, a string will work in place of a symbol, but definitely not always. In those cases where you need a symbol, you can use the string's "to_sym" method to convert it to a symbol.

Railscasts - Free Ruby on Rails Screencasts