我正在處理連接到SQL Server 2008數據庫的Ruby 1.8/Rails 2.1應用程序。使用find_by_ <field>返回「表不存在」錯誤
當我嘗試使用find_by_CompanyCode
方法時,ActiveRecord返回一個NoMethodError。然而,從下面你可以看到表格存在並且有問題的方法。
不知道我很想念..任何幫助將不勝感激
編輯:只有那些在結束「代碼」字段沒有出現的時候我就跑IvantageEmployee.first ..從視圖中出現錯誤。將完全相同的代碼移動到控制器,代碼按預期工作。
eval @goal.organization_type.employee_class + ".find_by_#{@goal.organization_type.employee_field_code}('#{@goal.specifier}').#{@goal.organization_type.employee_field_description}"
>> IvantageEmployee.first.CompanyCode => "GAI" >> IvantageEmployee.find_by_CompanyCode('GAI') NoMethodError: undefined method `find_by_CompanyCode' for IvantageEmployee(Table doesn't exist):Class from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1613:in `method_missing_without_paginate' from /usr/lib/ruby/gems/1.8/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb:170:in `method_missing' from (irb):7 >>
一些更多的信息。該表有幾個字段。我正在努力的是CompanyCode,但它也有RegionDescription。
請注意以下控制檯輸出。 find_by_RegionDescription起作用; find_by_CompanyCode不起作用。此外,企業編碼沒有出現,當我剛剛輸出的類別,但RegionDescription不會不知道爲什麼ActiveRecord的將缺少在桌子上
>> IvantageEmployee.find_by_RegionDescription 'GAI' ### Finding method find_by_RegionDescription => nil >> IvantageEmployee.find_by_CompanyCode 'GAI' ### Finding method find_by_CompanyCode NoMethodError: undefined method `find_by_CompanyCode' for IvantageEmployee(Table doesn't exist):Class from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1614:in `method_missing_without_paginate' from /usr/lib/ruby/gems/1.8/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb:170:in `method_missing' from (irb):9 >>
不是一個修復,但我把原來導致這個錯誤的代碼從一個視圖移到了一個控制器,並且它工作。不知道爲什麼。 – Greg