我試圖使用只有被稱爲在我的控制器的具體方法一些驗證:是否可以驗證自定義方法?
validates_presence_of :reasons, :on => :update_description
但是我得到這個錯誤:
TypeError in RegistrationsController#create
nil is not a symbol
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:586:in `send'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:586:in `validates_presence_of'
/Users/blah/Desktop/testApp/app/models/registration.rb:6
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:380:in `load_without_new_constant_marking'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:380:in `load_file'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:379:in `load_file'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:259:in `require_or_load'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:425:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:437:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:96:in `const_missing'
/Users/blah/Desktop/testApp/app/controllers/registrations_controller.rb:81:in `create'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1331:in `send'
我要對這個錯誤的方式?基本上我有一個多頁面的表單,我已經把這些頁面分成了他們提交的多個更新方法。在這種情況下,我使用我定義的名爲update_description的方法更新註冊對象。我只希望在調用此方法時進行驗證。可能?
更新: 添加錯誤行:
def create
@registration = Registration.new(params[:registration]) //error is here
[nav logic]
end
請發佈什麼在這裏:registrations_controller.rb:81:在'創建' – marcgg 2010-01-29 16:15:35
我加上了 – Jeff 2010-01-29 16:34:09