문제

내 레일 앱은 로컬에서 잘 작동합니다. 그러나 일단 서버와 생산 모드에 넣으면이 오류가 발생합니다.

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

객체를 현재 동작에 전달 해야하는 경우 지금 사용하면 현재 작업이 완료되면 물체가 사라집니다.

지금을 통해 설정된 항목은 표준 항목과 동일한 방식으로 액세스됩니다 : Flash [ 'my-key'].

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top