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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Mar 2008, at 15:38, Tom Ha wrote:> > 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. >Looks like you want> Message.update_all (:read => true, :target_id => session[:user_id])Fred> The error that I get is: > > .../app/controllers/message_controller.rb:4: syntax error, > unexpected '')'', expecting tASSOC > > Thank you very much! > Tom > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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) Frederick Cheung wrote:> On 27 Mar 2008, at 15:38, Tom Ha wrote: > >> 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. >> > Looks like you want >> Message.update_all (:read => true, :target_id => session[:user_id]) > > Fred-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Mar 2008, at 16:01, Tom Ha wrote:> > 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> > Frederick Cheung wrote: >> On 27 Mar 2008, at 15:38, Tom Ha wrote: >> >>> 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. >>> >> Looks like you want >>> Message.update_all (:read => true, :target_id => session[:user_id]) >> >> Fred > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tom Ha wrote:> Message.update_all (:read => true, ''target_id > #{session[:user_id]}'')Also note that #{} doesn''t interpolate in single quotes, so you probably want to use double quotes here... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks guys! (I lost my afternoon, but you saved my evening... :-) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tom Ha writes> > Hi there, > > can anyone please tell me what''s wrong with the following line? (Itmust> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---