0
任何手头上的专家对于我所确信的都是一个快速解决方案。我正在运行sinatra与红宝石控制器&模型,与erb视图文件。我只想查询postgres-db并显示那条数据。我有一个类似的功能,可以返回我想要的,但是这个不会。任何帮助非常感谢。索引获取请求时没有方法错误ruby
预算模型:
def self.total
sql = "SELECT SUM(value) FROM budgets"
response = SqlRunner.run(sql).first
return response["sum"]
end
控制器:
get '/budgets' do
@budgets = Budget.all
@budget_total = Budget.total
erb(:'budgets/index')
end
视图/ ERB:
<p> Total budget: <%= @budget_total %> </p>
什么行导致错误? –
@budget_total = Budget.total是错误的地方。它根本无法识别该功能。 – godhar
你能粘贴错误吗? – Dias