일부 Rails 3.1 중간 크기의 응용 프로그램에서 작업 중이며 로컬 서버를 시작한 후 임의로 발생하는 이상한 문제가 발생했습니다.Rails 3.1 정말 이상한 문제가 임의로 발생합니다
서버가 시작된 후 실제로 자주 발생합니다. 매번 그렇지는 않지만 정의되지 않은 방법 인 에 대해 실제로 정의됩니다.입니다.
그때 바로 응용 프로그램 충돌을 행하기 전에 몇 가지 binding.pry 또는 디버거을 넣어 나 자신에게 내가 예상 결과를 (아무 충돌)을 얻을하는 방법을 사용 하려고합니다. 디버깅 콘솔을 종료하면 서버가 정상 상태로 돌아갑니다. 예를 들어
내가 얻을 :
NoMethodError (undefined method `type=' for #<Publication:0xb398f180>): app/controllers/publications_controller.rb:115:in `new'
내가 그 컨트롤러를 이동하고, binding.pry
@publication = current_user.publications.new
binding.pry
@publication.type = type
히트 새로 고침을 추가 콘솔이를 입력하면
Publication.new.type = PublicationType.first
콘솔을 나가면 서버가 정상 상태로 돌아갑니다.
이것은 내 로컬 환경에서만 발생하는 것으로 보입니다. 생산에 배치하거나 사양을 실행 한 후에 이러한 문제가 발생하지 않았습니다.
저는 그 사람이 나쁘지는 않지만 곧 다른 개발자가 코드 기반에서 작업 할 것이므로 실제 문제가 될 것입니다.
편집 : 오늘이 다른 오류로 실행
:
= link_to truncate(comment.publication.title, :length => 30), comment.publication, :class => "category-font #{comment.publication.color_class}"
다음 난 그냥 binding.pry 트릭을했고
comment.publication.color_class
를 입력에서 undefined method `color_class' for #<Publication:0xb39e44f0>
...
편집
는 콘솔을 떠나 모든 것을 잘 갔다 :
좋아 지금은 더 이상 취득을 ... 나는 위와 같은 문제로 실행
의 color_class one. 설명 트릭이 작동하지 않는이 시간을 제외하고, 출력 올립니다 참조 :3: = link_to publication_path(comment.publication, :anchor => "comment-#{comment.id}") do 4: = link_to comment_excerpt(comment), comment_link(comment), :class => "comment_excerpt" 5: \- 6: = link_to comment.author.username, comment.author 7: \- => 8: - binding.pry 9: = link_to truncate(comment.publication.title, :length => 30), comment.publication, :class => "category-font #{comment.publication.color_class}" [1] pry(#>)> comment.publication.color_class NoMethodError: undefined method `color_class' for # from /home/jerefrer/.rvm/gems/ruby-1.8.7-p352/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:385:in `method_missing' [2] pry(#>)> comment.publication.category NoMethodError: undefined method `category' for # from /home/jerefrer/.rvm/gems/ruby-1.8.7-p352/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:385:in `method_missing' [3] pry(#>)> comment.publication.id => 139 [4] pry(#>)> comment.publication == Publication.find(139) => false [5] pry(#>)> Publication.find(139).color_class => "some-class"
을 그리고 난 그냥 같은 오류가 점점 계속 ... 어떤 트릭이 시간을 찾을 수 없습니다 ...
편집 3 :
그리고 새!
> Comment.includes(:publication => :author).order('created_at DESC').limit(10)
Hirb Error: Association named 'author' was not found; perhaps you misspelled it?
> Comment.order('created_at DESC').limit(10)
[is working]
> Comment.order('created_at DESC').limit(10).first.author
[is working]
어떤 아이디어가 있습니까?
는 Publication', 당신은해야'ActiveRecord' 모델이다'가정 Single Table Inheritance의 일부분을 제외하고는'type'을 사용하지 말라. 너? – Chowlett
@Chowlett 실제로 게시 belongs_to : type, : foreign_key => "publication_type_id", : class_name => "PublicationType"이 있습니다. 필자는 이것을 편리하게 만들었지 만이 문제를 방지 할 수 있는지 모든 곳에서 publication_type을 사용하려고합니다. 어쨌든 비슷한 문제 (게시 수정 참조)가 있지만이 '유형'입력란과 관련이 없습니다. –