Rails 3 NoMethodError未定義のメソッド `name '

コメントオブジェクトにcomment.saveを呼び出すとエラーが表示され、これをデバッグするのに役立ちますか?

出力は次のとおりです。

NoMethodError: undefined method `name' for #
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/attribute_methods.rb:364:in `method_missing'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/attribute_methods.rb:46:in `method_missing'
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/errors.rb:224:in `read_attribute_for_validation'
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/errors.rb:224:in `send'
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/errors.rb:224:in `add_on_blank'
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/errors.rb:223:in `each'
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/errors.rb:223:in `add_on_blank'
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/validations/presence.rb:9:in `validate'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/callbacks.rb:314:in `send'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/callbacks.rb:314:in `_callback_before_1143'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/callbacks.rb:414:in `_run_validate_callbacks'
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/validations.rb:212:in `run_validations!'
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/validations/callbacks.rb:67:in `run_validations!'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/callbacks.rb:413:in `_run_validation_callbacks'
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/validations/callbacks.rb:67:in `run_validations!'
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.5/lib/active_model/validations.rb:179:in `valid?'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/validations.rb:55:in `valid?'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/validations.rb:75:in `perform_validations'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/validations.rb:43:in `save'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/attribute_methods/dirty.rb:21:in `save'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:240:in `save'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:292:in `with_transaction_returning_status'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:207:in `transaction'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:240:in `save'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:251:in `rollback_active_record_state!'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:239:in `save'
    from (irb):645
    from :0>> 

...

this happens after running:

c = event.comment.new
c.body = "test comment"
c.save

I've read a lot of threads saying that this is an issue with Rails version and Rubygems version but I find that hard to believe.

1
モデル定義を質問に追加します。
追加された 著者 lucapette,

1 答え

次のいずれか:

  1. you have a show or index view with a call to name i.e comment.name
  2. you have a validation on name in your comments model

あなたが与えた情報からは分かりません。どこでエラーが出ますか?

5
追加された
はい、#2が正しいです。それに感謝します。移行後に私のモデルを更新するのは慎重ではありませんでした。私のモデルはまだ私がモデルで検証していた「名前」フィールドを含んでいました。レールのエラーに慣れるだけです:)もう一度感謝します。
追加された 著者 botbot,