开发环境中没有错误但生产中没有错误

时间:2014-07-19 16:34:21

标签: ruby-on-rails ruby development-environment null

在我本地计算机上的rails开发环境中,当访问我的应用程序的“财务”页面时,我收到以下“nil”错误消息。有趣的是,在生产中,“财务”页面显示正确,没有错误。

经过数天的试验和错误,试图查看登录供应商(用户)为什么抛出'nil',我在这里。我对编程有点偏高,所以我的预感是开发和生产数据库在某种程度上有所不同,从而导致开发环境中供应商的“零”结果?无论如何,我不知道从哪里开始。错误消息和development.rb中的引用文件也包含在下面。任何帮助将不胜感激。 Rails(3.2.17),Ruby(1.9.3 p545)

错误讯息:

NoMethodError in Financials#income_statement 

Showing /home/vagrant/umarkit/app/views/financials/income_statement.html.erb where line #24 raised: 
undefined method `[]' for nil:NilClass
Extracted source (around line #24): 

21:   </tr>
22:   <tr><td class="lft"><%= t('financial_statements.revenues_html') %></td>
23:     <% @income_statemens.each do |incomestatement| %>
24:        <td class="lft"><%=number_to_financials(incomestatement.revenues)%></td>
25:     <% end %>
26:   </tr>
27:   <tr><td class="lft"><%= t('financial_statements.cogs_html') %></td>

Rails.root: /home/vagrant/umarkit

Application Trace: 

app/views/financials/income_statement.html.erb:24:in `block in app_views_financials_income_statement_html_erb___1058489885_86848080'
app/views/financials/income_statement.html.erb:23:in `each'
app_views_financials_income_statement_html_erb___1058489885_86848080'
app/controllers/financials_controller.rb:36:in `income_statement'

app / views / financials / income_statement.html.erb

<h1 class="sectionTitle">Income Statement</h1>

<div class="filterRange">
  <%= form_tag('/financials/income_statement', :method => 'get') do %>
  <label>Show Statement for:
    <%= select_tag 'year', options_for_select((@year-10)..(@year+5), @year) %>
  </label>
  <input type="submit" class="btn-showFilter" value="Show">
  <% end %>
</div>

<div class="filterState">
  <p>Showing Year: <%= @year %></p>
</div>
<% if !@income_statemens.nil? %>
<table class="utable">
  <tr><th class="lft nwp" width="350"><%= t('financial_statements.year_html') %></th>
    <% @income_statemens.each do |incomestatement| %>
       <th class="lft" width="534"><%=incomestatement.year%></th>
    <% end %>
  </tr>
  <tr><td class="lft"><%= t('financial_statements.revenues_html') %></td>
    <% @income_statemens.each do |incomestatement| %>
       <td class="lft"><%=number_to_financials(incomestatement.revenues)%></td>
    <% end %>
  </tr>
  <tr><td class="lft"><%= t('financial_statements.cogs_html') %></td>
    <% @income_statemens.each do |incomestatement| %>
       <td class="lft"><%=number_to_financials(incomestatement.cogs)%></td>
    <% end %>

应用程序/控制器/ financials_controller.rb

class FinancialsController < ApplicationController
  before_filter :authenticate_vendor!

  # GET /financials
  # GET /financials.xml
  def index
    @vendor = current_vendor
    if @vendor != nil
      @financials = @vendor.get_financial_statements
    end

    if @financials == nil
      flash.now[:error] = "No transactions available."
    end
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @financials }
    end
  end

  def income_statement
    @vendor = current_vendor

    @year = params[:year] ? params[:year].to_i : Date.today.year

    puts @vendor.methods

    if @vendor != nil
      @income_statemens = @vendor.get_income_statement(@year)
      @income_statemens = @income_statemens.incomestatements
    end

    if @income_statemens == nil
      flash.now[:error] = "No transactions available."
    end
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @income_statemens }
    end
  end

  def balance_sheet
    @vendor = current_vendor

    @year = params[:year] ? params[:year].to_i : Date.today.year

    if @vendor != nil
      @balance_sheet = @vendor.get_balance_sheet(@year)
      @balance_sheet = @balance_sheet.balancesheets
    end

    if @balance_sheet == nil
      flash.now[:error] = "No transactions available."
    end
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @balance_sheet }
    end
  end

  def cash_flow
    @vendor = current_vendor

    @year = params[:year] ? params[:year].to_i : Date.today.year

    if @vendor != nil
      @cash_flow = @vendor.get_cash_flow(@year)
      @cash_flow = @cash_flow.cashflows
    end

    if @cash_flow == nil
      flash.now[:error] = "No transactions available."
    end
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @cash_flow }
    end
  end

  def show_transactions
    @vendor = current_vendor
    if @vendor != nil
      @transactions = @vendor.get_transactions
    end

    if @transactions == nil
      flash[:error] = "No transactions available, or First Date Stamp is nil."
    end
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @entries }
    end
  end
end

development.rb

Ketch::Application.configure do
  # Settings specified here will take precedence over those in config/environment.rb

  # In the development environment your application's code is reloaded on
  # every request.  This slows down response time but is perfect for development
  # since you don't have to restart the webserver when you make code changes.
  config.cache_classes = false

  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

  # Only use best-standards-support built into browsers
  config.action_dispatch.best_standards_support = :builtin

  # Devise Configuration
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }

  config.assets.debug = true
end

1 个答案:

答案 0 :(得分:0)

我会测试数据不同的假设,因为Rails使用不同的数据库进行开发,测试和生产环境。尝试重置基础数据并确认。

相关问题