2014-07-19 58 views
-1

在本地機器上的rails開發環境中,當訪問我的應用程序的「財務」頁面時,我收到下面的'nil'錯誤消息。有趣的是,在生產中,'財務'頁面正確顯示,沒有錯誤。開發環境中沒有錯誤但生產中沒有錯誤

經過幾天的試驗和錯誤,試圖瞭解爲什麼登錄的供應商(用戶)拋出'零',我在這裏。我對編程有點綠色,所以我的直覺是開發和生產數據庫在某種程度上有所不同,從而導致開發環境中供應商的'零'結果?無論如何,我不確定該從哪裏出發。錯誤消息和development.rb中的引用文件也包含在下面。任何援助將不勝感激。軌(3.2.17),紅寶石(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' 

應用/視圖/金融/ 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 [email protected]_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 

回答

0

我會測試數據不同的假設,因爲Rails在開發,測試和生產環境中使用不同的數據庫。嘗試重置底層數據並確認。

相關問題