2010-07-14 4 views
0

이것은 그것이 착륙하는 라인입니다. 루비 온 레일즈 (Ruby on Rails) : 정의되지 않은 메소드`call 'for nil : NilClass

@object = Object.find(params[:id]) 

    respond_to do |format| 
     if @object.update_attributes(:status=>Object::PUBLISHED, :published_at => Time.now) 
     format.html { redirect_to :action => :publish_detail } 
     format.xml { head :ok } 
     format.json { head :ok } 
    #else 
    # flash[:error] = 'There was a problem updating your object.' 
    # format.html { redirect_to :action => "publish_detail" } 
    # format.xml { render :xml => @object.errors, :status => :unprocessable_entity } 
    # format.json { render :json => @object.errors, :status => :unprocessable_entity } 
    end 
end 

스택
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/whiny_nil.rb:52:in `method_missing' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:175:in `respond' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:173:in `each' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:173:in `respond' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:107:in `respond_to' 
.../app/controllers/objects_controller.rb:252:in `publish' 

왜이 오류가 발생하는 것입니다 추적?

제가
puts "||||||||||||||||||#{@object.name}" 

을 첨가하고, 콘솔 로그 도시

\ 객체가없는 무 .. =임을 보여준다

NoMethodError (undefined method `call' for nil:NilClass): 
    app/controllers/objects_controller.rb:252:in `publish' 

Rendered rescues/_trace (26.1ms) 
Rendered rescues/_request_and_response (1.1ms) 
Rendering rescues/layout (internal_server_error) 
+0

전체 respond_to 차단을 게시 할 수 있습니까? –

+0

오류와 더 많은 코드에서 스택 추적을 게시 할 수 있습니까? –

+0

=) 모든 것을 스택 트레이스 – NullVoxPopuli

답변

1

(레일 2.3.8에서) date_select를 사용하여 datetime을 설정할 수 없기 때문에이 오류가 발생했습니다.

그래서 f.date_select를 f.datetime_select로 변경하고 날짜를 다시 저장하면 모든 것이 잘되었습니다.

3

뜻 ... 어. .. "nil"개체에 대해 "call"메서드를 호출하려고합니다.

개체를 사용할 수 없다고 생각하면이 문제가 발생합니다. 이는 예일 수 있습니다. Object.find가 객체를 찾을 수없는 경우 "nil"을 반환합니다.

@object는 "nil"이되고 Object 유형 인 것처럼 처리 할 수 ​​없습니다.

편집 : 항상 "nil?"을 사용하여 확인하십시오. provenience가 불확실한 객체를 사용하기 전에.

관련 문제