代码之家  ›  专栏  ›  技术社区  ›  Asantoya17

谷歌铁轨上的图表

  •  0
  • Asantoya17  · 技术社区  · 13 年前

    你好,我一直在读关于如何在rails上使用谷歌图表制作图表的文章,我已经安装了插件,但我不知道为什么会显示这个错误:

    NameError in TankingLogsController#index
    
    uninitialized constant TankingLogsController::GoogleChart
    

    这是我的inde.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'
    
    2 回复  |  直到 13 年前
        1
  •  2
  •   Peter DeWeese    13 年前

    我通过重新启动服务器解决了问题。

        2
  •  0
  •   Harley Sugarman    13 年前

    您应该确保宝石在您的宝石文件中:

    gem 'google-charts-on-rails'
    

    否则,即使你的系统上安装了gem,应用程序也不会使用它。