1

我正在使用 rails 2.3.4,我面临“无方法错误”

有可能找不到方法,但我的问题是 - 是否有可能因为空表而发生错误?或另一个控制器或助手中的错误?

错误跟踪:

处理 QuoteRequestsController#create (for 127.0.0.1 at 2012-10-17 16:07:34) [POST] 参数:{"controller"=>"quote_requests", "quote_request"=>{"packing_required"=>"", "move_steps_number"=>"", "phone_day"=>"", "pickup_region_id"=>"", "email"=>"", "move_to_street"=>"", "move_from_suburb"=>"", "title "=>"", "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'

供应商/辐射/供应商/插件/haml/rails/./lib/sass/plugin/rails.rb:19:in `process'

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/httpserver.rb:104:in `服务'

/home/bacancy/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/webrick/httpserver.rb:65:在“运行”中

/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:in `start'

/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 `每个'

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

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

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

在“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')返回nil(这只是意味着您的service_descriptions表中没有带有 name的数据'region')然后您正在调用service_options它(即nil

避免这种情况的最好方法是在应用任何方法之前检查 value 是否为 nil。

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