Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 索引get请求ruby中没有方法错误_Sql_Ruby_Sinatra - Fatal编程技术网

Sql 索引get请求ruby中没有方法错误

Sql 索引get请求ruby中没有方法错误,sql,ruby,sinatra,Sql,Ruby,Sinatra,任何专家在场,我相信这是一个快速解决办法。我使用ruby控制器和模型运行sinatra,并使用erb视图文件。我只想查询postgres数据库并显示该数据段。我有一个类似的函数,返回我想要的,但这个函数没有。非常感谢您的帮助 预算模式: def self.total sql = "SELECT SUM(value) FROM budgets" response = SqlRunner.run(sql).first return response["sum"] en

任何专家在场,我相信这是一个快速解决办法。我使用ruby控制器和模型运行sinatra,并使用erb视图文件。我只想查询postgres数据库并显示该数据段。我有一个类似的函数,返回我想要的,但这个函数没有。非常感谢您的帮助

预算模式:

  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
视图/雇员再培训局:

<p> Total budget:  <%= @budget_total %> </p>
预算总额:


现在它可以工作了,没有错误,没有变化,撬杆也能迅速上升。一时兴起


结论:有时你只需要把机器收起来,到森林里去散步。

是哪一行导致了错误?@budget\u total=budget.total就是错误所在。它根本无法识别该函数。你能粘贴错误吗?预算的未定义方法“total”:Class>>第10行@Budget\u total=Budget.total>/.rbenv/versions/2.4.0/lib/ruby/2.4.0/webrick/httpserver.rb实际上只需崩溃,然后重新启动Sinatra web服务器。其他方法都失败了,试试看。