gpt4 book ai didi

ruby-on-rails - Rails 4.0 未定义方法 `call'

转载 作者:太空宇宙 更新时间:2023-11-03 18:17:40 24 4
gpt4 key购买 nike

我有一个 Rails 应用程序,我正在创建一个 highcharts 折线图来比较两个行业的股票,电信和农业,同时关注 this , ryan bates highstocks 视频。

图表将输出到stock_quotes 的index.html.erb View 中,highcharts 的javascipt 代码如下:

<div id="quotes_chart", style="width=560px; height:300px;">

$(function(){
new HighCharts.Chart(
chart: {
renderTo: "quotes_chart"
},
title: {
text: "Daily trades"
},
xAxis: {
type: "datetime"
},
yAxis: {
title: {
text: "Shillings"
}
},
tooltip: {
formatter: function(){
return HighCharts.dateFormat("%B %e, %Y", this.x) + ': ' + "Kshs" + Highcharts.numberFormat(this.y, 2);
}
},
series: [
<% { "Telecommunication" => StockQuote.telecomm, "Agriculture" => StockQuote.agric }.each do |name, prices|
%>
{
name: <%= name %>
pointInterval: <%= 1.day * 1000 %>,
pointStart: <%= 2.weeks.ago.to_i * 1000 %>,
data: <%= (2.weeks.ago.to_date..Date.today).map { |date| StockQuote.price_on(date).to_f}.inspect%>
},
<% end %>]
});
});
</div>

模型stock_quote.rb如下:

scope :agric, where(category: "Agriculture")
scope :telecomm, where(category: "Telecommunication")

def self.price_on(date)
where("date(published_at) = ?", date).sum(:total_price)
end

这是在 stock_quotes div 上输出的内容:

$(function(){ new HighCharts.Chart( chart: { renderTo: "quotes_chart" }, title: { text: "Daily trades" }, xAxis: { type: "datetime" }, yAxis: { title: { text: "Shillings" } }, tooltip: { formatter: function(){ return HighCharts.dateFormat("%B %e, %Y", this.x) + ': ' + "Kshs" + Highcharts.numberFormat(this.y, 2); } }, series: [ { name: Telecommunication pointInterval: 86400000, pointStart: 1398157330000, data: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 554.0] }, { name: Agriculture pointInterval: 86400000, pointStart: 1398157330000, data: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 554.0] }, ] }); }); 

最佳答案

rails 4 scope syntax相反:

  scope :agric, where(category: "Agriculture")
scope :telecomm, where(category: "Telecommunication")

使用:

  scope :agric, -> { where(category: "Agriculture") }
scope :telecomm, -> { where(category: "Telecommunication") }

关于ruby-on-rails - Rails 4.0 未定义方法 `call',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23490081/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com