views:

121

answers:

3

Where is the error in this I can't see it:

news = News.find(:all, :conditions => [":simulation_id => session[:sim_id] AND :created_at > session[:last_login]"])
+5  A: 

Try this:

news = News.find(:all, :conditions => ["simulation_id = ? AND created_at > ?", session[:sim_id], session[:last_login]])
Chris Doggett
+1  A: 

Your conditions string won't be evaluated as you expect:

[":simulation_id => session[:sim_id] AND :created_at > session[:last_login]"]

change that to

["simulation_id = ? AND created_at > ?", session[:sim_id], session[:last_login]]
Mr. Matt
simulation_id should be '=', not '=>'
Chris Doggett
oops - yeah, fixed that
Mr. Matt
A: 

You can also call Model.all instead of Model.find(:all) which would look something like this:

news = News.all(:conditions => ["simulation_id = ? AND created_at > ?", session[:sim_id], session[:last_login]])
Scott