session[:sim_id] AN...">

Rails syntax error

Where is the error in this, I cannot see it:

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

      

0


a source to share


3 answers


Try the following:



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

      

+5


a source


The condition string will not evaluate as you expect:

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

      



change it to

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

      

+1


a source


You can also call Model.all

instead Model.find(:all)

, which will look something like this:

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

      

0


a source







All Articles