1

さまざまなデータセット間の比較を生成するために、舞台裏でいくつかのプロットを行うRailsアプリを開発しています。私が見ているのはActionView::Template::Error、DataMapperデータベースでのComparisonオブジェクトの生成に関する散発的な500エラー()です。これは、あるマシンで時々発生し、別のマシンで毎回発生し、1台では発生しません。これらのエラーはコンピューターのパフォーマンスと相関関係があり、DataMapperが舞台裏で何か奇妙なことをしていると私は信じています。

私は「なぜ」を追いかけるのをあきらめ、今は500エラーをキャッチし、レビュー担当者に問題が表示されないように強制的に更新しようとしています。しかし、私が試したすべてがうまくいきませんでした。これが私の設定です:

比較コントローラー.rb

# This is the action which allows for generation of a new comparison.  It uses a fork to spawn a child process which generates the comparison. Notifications will appear when this fails or finishes.  
  def create
    first_set = get_msruns_from_array_of_ids(params[:comparison1].uniq)
    second_set = get_msruns_from_array_of_ids(params[:comparison2].uniq)

    comp = Comparison.new
    comp.msrun_firsts = first_set
    comp.msrun_seconds = second_set
    comp.first_description = params[:first_description]
    comp.second_description = params[:second_description]
    comp.save

# This should capture the windows fork and prevent it.
    if RbConfig::CONFIG['host_os'] === 'mingw32'
      redirect_to :action => "show", :id => comp.id
      result = comp.graph
      a = Alert.create({ :email => false, :show => true, :description => "DONE WITH COMPARISON #{comp.id}" })
    else
      fork do
        result = comp.graph
        a = Alert.create({ :email => false, :show => true, :description => "DONE WITH COMPARISON #{comp.id}" })
      end
      flash[:notice] = "Comparison started. You will be notified when it completes."
 # HERE I've attempted to capture problem 
      begin 
        render :action => "show"
      rescue 
        redirect_to :action => "show", :id => comp.id
      end 
    end

これは私のproduction.logファイルに表示されます:

ActionView::Template::Error (undefined method `first_description' for nil:NilClass):  
    1: /- @comparison ||= Comparison.get(params[:id])
    2: /%h1= "Comparison ##{@comparison.id}"
    3: %p <strong>User Description: </strong>
    4: <p> Set#1: #{ @comparison.first_description }
    5: <p> Set#2: #{@comparison.second_description }
    6: <p> #{link_to "Edit", edit_comparison_path(@comparison)}
    7: %ul.categories
  app/views/comparisons/show.html.haml:4

このエラーは何週間も私を悩ませてきましたが、私には何も起こりませんでした。エラーをキャッチして強制的に更新する理由または方法に関するアイデアはありますか?

ありがとう。

4

1 に答える 1

1

@comparisonビュー内にロードするべきではありません。それはコントローラーの責任です。また、実際に割り当てる行をコメントアウトした@comparisonので、それが として評価されても驚くことではありませんnil

oncreateには:idパラメータがまったくないことに注意してください。これは、最終的にその情報が利用可能になったときにリダイレクトでのみ機能する理由を説明するかもしれません.

あなたがおそらく意味したのはこれでした:

@comparison = Comparison.new

これにより、パラメーターに関係なく、ビュー内で使用する変数が定義されます。

于 2012-01-30T17:16:09.167 に答える