1

Rails 2.3.4 を使用していますが、「no method error」に直面しています

メソッドが見つからない可能性がありますが、私の質問は、空のテーブルが原因でエラーが発生する可能性はありますか? または別のコントローラーまたはヘルパーでエラーが発生しましたか?

エラー トレース:

QuoteRequestsController#create の処理 (2012-10-17 16:07:34 の 127.0.0.1 用) [POST] パラメータ: {"controller"=>"quote_requests", "quote_request"=>{"packing_required"=>"", "move_steps_number"=>"", "phone_day"=>"", "pickup_region_id"=>"", "email"=>"", "move_to_street"=>"", "move_from_suburb"=>"", "タイトル"=>"", "quick_estimate"=>"true", "room_counts"=>{"9"=>"0", "8"=>"0", "5"=>"0", "2 "=>"0", "3"=>"0", "6"=>"0", "7"=>"0", "1"=>"0", "4"=>"", "11"=>"0"}, "arrive_parking_notes"=>"", "first_name"=>"", "arrive_date_flexible"=>"false"," Insurance_value"=>"", "arrive_steps_number"=>"", "move_parking_notes"=>"", "last_name"=>"", "move_region_id"=>"", "move_date_flexible"=>"false", "move_type_id "=>"26", "move_to_city"=>"", "arrive_date"=>"", "move_from_street"=>"", "move_date"=>"", "move_to_suburb"=>"", "move_from_city" =>"", "phone_mobile"=>""}, "authenticity_token"=>"U42qF1c0FJXvnC1SCNNYWzxKN3Pem7dC6L01LbTQD7E=", "commit"=>"Submit", "action"=>"create"}

NoMethodError (未定義のメソッドservice_options' for nil:NilClass): vendor/extensions/smartmove/app/controllers/quote_requests_controller.rb:136:inload_regions'

vendor/radiant/vendor/plugins/haml/rails/./lib/sass/plugin/rails.rb:19:「プロセス」内

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/httpserver.rb:104:「サービス」内

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/httpserver.rb:65: in `run'

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/server.rb:162:「開始」

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/server.rb:95:in `start'

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/server.rb:92:in `each'

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/server.rb:92:「開始」

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/server.rb:23:「開始」

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/server.rb:82:「開始」

「vendor/extensions/smartmove/app/controllers/quote_requests_controller.rb」の行番号:136は

@regions = ServiceDescription.find_by_name('region').service_options

私のデータベース テーブルには、service_descriptions と service_options があります。mysqlまたはコントローラーに関連していますか?私を案内してください私は非常に混乱しています。これは、サーバーだけでなくローカルでも構成する必要がある既存のアプリケーションです

前もって感謝します

ありがとうニラフ

4

1 に答える 1

1

エラーがServiceDescription.find_by_name('region')返されるため (これは単にname のテーブルにnilデータがないことを意味します)、それを呼び出しています (つまり)service_descriptions'region'service_optionsnil

このようなケースを回避する最善の方法は、メソッドを適用する前に値が nil かどうかを確認することです。

@regions = ServiceDescription.find_by_name('region')
@service_options = @regions ? @regions.service_options : nil
于 2012-10-17T11:21:55.453 に答える