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