您好,我一直在阅读有关如何使用 google-charts-on-rails 制作图表的信息,我已经安装了插件,但我不知道为什么会显示此错误:
NameError in TankingLogsController#index
uninitialized constant TankingLogsController::GoogleChart
这是我的 indes.html.erb
<div class="container">
<%= image_tag @bar %>
<h1>Listing Tankings</h1>
<% if @tankinglog.count<1 %>
<p>
There are no tankings for this car. Do you want to <%= link_to 'create a new tanking', new_user_car_tanking_log_path(@user, @car)%>
</p>
<% else %>
<table class="table table-condensed">
<tr>
<th>Cost</th>
<th>Gallon</th>
<th>Km</th>
<th>Date</th>
<th>Gas Station's id</th>
<th></th>
</tr>
<% @tankinglog.each do |tankinglog| %>
<tr>
<td><%= tankinglog.cost %></td>
<td><%= tankinglog.gallon %></td>
<td><%= tankinglog.km %></td>
<td><%= tankinglog.date %></td>
<td><%= tankinglog.gas_station_id %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New tanking', new_user_car_tanking_log_path(@user, @car), :class => "btn btn-primary" %>
<% end %>
<br />
<br />
<%= link_to 'back', user_cars_path(current_user), :class => "btn btn-primary" %>
</div>
这是我的控制器
class TankingLogsController < ApplicationController
....
def index
@user = User.find(params[:user_id])
@car = @user.cars.find(params[:car_id])
@tankinglog = @car.tanking_logs.all
@bar = GoogleChart.pie(['1997',10],['1998',20],['1999',40],['2000',30]).to_url
end
end
我的宝石文件
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'pg', '0.13.2'
gem 'devise', '2.0.4'
gem 'haml-rails'
gem 'twitter-bootstrap-rails', '2.0.6'
gem 'sass-rails', '~> 3.2.3'
gem "rspec", "~> 2.10.0"
gem 'simplecov', :require => false, :group => :test
gem 'gchart'