哪裏錯誤在此,我不能看到它:Rails的語法錯誤
news = News.find(:all, :conditions => [":simulation_id => session[:sim_id] AND :created_at > session[:last_login]"])
哪裏錯誤在此,我不能看到它:Rails的語法錯誤
news = News.find(:all, :conditions => [":simulation_id => session[:sim_id] AND :created_at > session[:last_login]"])
試試這個:
news = News.find(:all, :conditions => ["simulation_id = ? AND created_at > ?", session[:sim_id], session[:last_login]])
你的條件字符串不會被評估爲你想到:
[":simulation_id => session[:sim_id] AND :created_at > session[:last_login]"]
變化,要
["simulation_id = ? AND created_at > ?", session[:sim_id], session[:last_login]]
您也可以撥打Model.all
代替Model.find(:all)
這將是這個樣子:
news = News.all(:conditions => ["simulation_id = ? AND created_at > ?", session[:sim_id], session[:last_login]])
simulation_id應該是 '=',而不是 '=>' – 2009-05-20 14:36:10