質問

私のRailsアプリはローカルでは正常に動作します。しかし、それをサーバーに配置して運用モードにすると、次のエラーが発生します。

ActionView::TemplateError (undefined method `each' for nil:NilClass) on line #7 of app/views/admin/confirm.rhtml:
4: <br>Description:
5: <br><%= @description %>
6: <br>Features:
7: <% @features.each do |feature| %>
8:      <br><%= feature.humanize %>
9: <% end %>
10: <br>Role data:

   app/views/admin/confirm.rhtml:7
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/renderable.rb:39:in `send'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/renderable.rb:39:in `render'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/template.rb:73:in `render_template'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/base.rb:256:in `render'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/base.rb:367:in `_render_with_layout'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/base.rb:254:in `render'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1174:in `render_for_file'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:896:in `render_without_benchmark'

それが何を意味するか知っている人はいますか?

編集:@features が nil であることがわかりました。しかし、それがどうなっているのかわかりません。私の作成アクションには次のものがあります。

flash[:name] = params[:name]
flash[:description] = params[:description]
flash[:role_data] = params[:role_data]
flash[:user_data] = params[:user_data]
flash[:features] = params[:features]
flash[:theme] = params[:theme]
redirect_to :action => "confirm"       

次に、確認アクションには次のようになります。

def confirm
    @title = "Create a new simulation"
    @features = flash[:features]
    @name = flash[:name]
    @description = flash[:description]
    @role_data = flash[:role_data]
    @user_data = flash[:user_data]
    @theme = flash[:theme]
    flash.keep
  end
役に立ちましたか?

解決

@features インスタンス変数は、そのインスタンスでは nil です。

他のヒント

おそらく、アクション間でデータを渡すにはセッション オブジェクトを使用する必要があります。Flash はアクション間でメッセージを渡すためのものであり、データを渡すためのものではありません。

置く必要があると思います flash.keep を使用しているため、作成アクションで redirect_to そしてそうではありません render.

から ActionController::Flash::FlashHash

現在のアクションにオブジェクトを渡す必要がある場合は、now を使用します。現在のアクションが完了するとオブジェクトは消えます。

now 経由で設定されたエントリには、標準エントリと同じ方法でアクセスできます。フラッシュ[「マイキー」]。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top