11175
(-- --)
March 27, 2008, 3:38pm
1
Hi there,
can anyone please tell me what's wrong with the following line? (It must
be so simple but I've been trying to find the error for so long...)
Message.update_all (:read => true, 'target_id =
#{session[:user_id]}')
This is supposed to set the attribute "read" to "true" (=1) where the
attribute "target_id" is equal to the user_id stored in the current
session.
The error that I get is:
.../app/controllers/message_controller.rb:4: syntax error,
unexpected ')', expecting tASSOC
Thank you very much!
Tom
Not really, because this would update NOT ONLY the :read attribute but
ALSO the :target_id attribute (which is not what I want...).
What I want it to do: update ONLY :read WHERE :target_id =
session[:user_id]
Can you spot the error in my statement above?
(I got some instructions from this page:
http://softiesonrails.com/2007/7/23/performing-a-sql-update-in-rails )
Oops. wasn't following closely enough. The basic issue is that you're
not allowed to drop the {} for a hash if there are normal parameters
coming after it.
Fred
Long
(Long)
March 27, 2008, 5:27pm
4
Tom Ha writes
Hi there,
can anyone please tell me what's wrong with the following line? (It
must
be so simple but I've been trying to find the error for so long...)
Message.update_all (:read => true, 'target_id =
#{session[:user_id]}')
I think you want #{session[:user_id} to resolve before the SQL update
so you need to change the single quote to double ("). Like
Message.update_all (:read => true, "target_id = #{session[:user_id]}")
even better yet,
Message.update_all (:read => true, "target_id =
'#{session[:user_id]}'")
-- Long
http://FATdrive.tv/wall/trakb/10-Long
http://FATdrive.tv/ - store, play, share
11175
(-- --)
March 27, 2008, 4:35pm
5
Thanks guys!
(I lost my afternoon, but you saved my evening...