2011-12-08 15 views
0

私はいくつかの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 

サーバーをただちに元の状態に戻すことができます。

これは私のローカル環境でのみ起こっているようです。本番環境にデプロイした後でも、仕様を実行しても、このような問題は発生しませんでした。

私は唯一の人だから、それほど悪くはないが、まもなく他の開発者がコードベースで作業するので、実際の問題になるだろう。

EDIT:

私は今日、この他のエラーに遭遇した:

undefined method `color_class' for #<Publication:0xb39e44f0> 

= link_to truncate(comment.publication.title, :length => 30), comment.publication, :class => "category-font #{comment.publication.color_class}" 

から、私はちょうどbinding.pryのトリックを行なったし、

comment.publication.color_class 
を入力 ...

EDIT

は、コンソールを離れ、すべてがうまくいった:

[OK]を、今それがさらに奇妙な取得を...私は、上記と同様の問題に遭遇した

、 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" 

をそして私はちょうど同じエラーを取得しておく...どんなトリックにこの時間を見つけるように見えることはできません...

EDIT 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] 

+1

をシングルテーブル継承の一部として以外は 'type'を使用しないでください。あなたですか? – Chowlett

+0

@Chowlett 実際には、私は出版物belongs_to:type、:foreign_key => "publication_type_id"、:class_name => "PublicationType"を持っています。 私はこれをちょっと便利にしましたが、どこにでもpublication_typeを使ってこの問題を防ぐことができるかどうか試してみましょう。 私は似たような問題に直面しています(編集後の記事を参照)。この "タイプ"フィールドには関係ありません。 –

答えて

1

シングルテーブル継承を使用していますか、タイプは定義した列だけですか?これが当てはまる場合、activerecordはデフォルトで、typeカラムが階層関係のサブクラスの名前を指定すると考えるので、実装していない場合は競合が発生する可能性があることに注意してください。 あなたが本当にその属性のタイプと呼ばれるように望んでいた場合、あなたはBase.inheritance_column

詳細情報上書きする必要があります:あなたは、Publication`は `ActiveRecord`モデルで`すべきであると仮定すると、http://code.alexreisner.com/articles/single-table-inheritance-in-rails.htmlhttp://api.rubyonrails.org/classes/ActiveRecord/Base.html(シングルテーブル継承セクション)

+0

"publication_type"をどこからでも使用して "type"をオーバーライドしないようにしましたが、エラーはまだ残ります... –