jr3 (63K)

Still a Ruby Newbie

Posted by closetmaster Sun, 12 Feb 2006 05:27:00 GMT

I am not sure why, but the following code generated errors for me: @pieces = Piece.find(:all, :conditions =>”user = ’#{@session[:user].id}’”)

I had to save the @session[:user].id, like this… tmp = @session[:user].id @pieces = Piece.find(:all, :conditions =>”user = ’#{tmp}’”)

This probabaly has something to do with ruby saving @session[:user].id as an string instead of an integer. I am having a similar problem right now in another portion of my code, I think. In order to show an image, I had to save the instance variable in the controller and then access it in the view rhtml file using piece3.picture. Update: In the Progamming Ruby: The Pragmatic Programmer’s Guide, the author notes that,

When Ruby constructs this string object, it looks at the current value of name and substitutes it into the string. Arbitrarily complex expressions are allowed in the #{...} construct. As a shortcut, you don’t need to supply the braces when the expression is simply a global, instance, or class variable.

I am guessing that @session[:user].id returns a value, so that when you try to take the value of the value @session[:user].id, you get some garbage.

Trackbacks

Use the following link to trackback from your own site:
/blog/articles/trackback/33

Comments

Leave a response

Comments


designed by jowensbysandifer