0

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'

誰でもそれが何を意味するのか分かりますか?

編集: OK @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
4

3 に答える 3

3

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

于 2009-03-25T09:38:36.847 に答える
0

and notflash.keepを使用しているので、 create アクションを入れる必要があると思います。redirect_torender

ActionController::Flash::FlashHashから

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

now 経由で設定されたエントリは、標準のエントリと同じ方法でアクセスされます: flash['my-key'].

于 2009-03-26T00:28:41.247 に答える