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'

有人知道这意味着什么吗?

编辑:好的,我发现@features 为零。但我不知道情况如何。在我的创建动作中,我有:

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 回答
1

对于该实例,您的 @features 实例变量为零。

于 2009-03-25T08:48:11.087 回答
0

我认为您需要flash.keep执行 create 操作,因为您正在使用redirect_to而不是render.

来自ActionController::Flash::FlashHash

当你需要将一个对象传递给当前动作时,你现在使用,当当前动作完成时你的对象就会消失。

通过 now 设置的条目的访问方式与标准条目相同:flash['my-key']。

于 2009-03-26T00:28:41.247 回答