1
我有一個find_by_sql語句,我試圖將位置ID傳遞給。我想我可以做這樣的事情:如何將一個url參數傳遞給rails3中的模型?
def self.location_history()
Location.find_by_sql("select * from locations a INNER JOIN hotspots b ON a.id = b.location_id INNER JOIN accounts c ON b.mac = c.account_id WHERE a.location_id= '#{id}'")
end
我想通下面將從URL拉id參數:
a.location_id = '#{id}'
然而拋出約未定義的變量錯誤。
我可以看到與請求一起發送的id =>'2'參數,但我不知道如何從模型中調用。如果可能的話?
Mucho gracias :) – simonmorley 2012-02-03 09:50:23
這實際上是一個錯誤:「錯誤的參數數量0表示1)「 – simonmorley 2012-02-03 10:01:20
我的錯誤,我忘了在我的視圖中更改爲@ location_history.each.do。 – simonmorley 2012-02-03 10:04:16