2009-05-20 61 views
0

哪裏錯誤在此,我不能看到它:Rails的語法錯誤

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

回答

5

試試這個:

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

你的條件字符串不會被評估爲你想到:

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

變化,要

["simulation_id = ? AND created_at > ?", session[:sim_id], session[:last_login]] 
+0

simulation_id應該是 '=',而不是 '=>' – 2009-05-20 14:36:10

0

您也可以撥打Model.all代替Model.find(:all)這將是這個樣子:

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