2010-01-29 41 views
0

我試圖使用只有被稱爲在我的控制器的具體方法一些驗證:是否可以驗證自定義方法?

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 
+1

請發佈什麼在這裏:registrations_controller.rb:81:在'創建' – marcgg 2010-01-29 16:15:35

+0

我加上了 – Jeff 2010-01-29 16:34:09

回答

1

的:在參數指定當這種驗證是有效(默認值是:保存,其它選項:創建:更新)。這與模型有關,而不是控制器。

+0

ahhhh我明白了。我對此有點不清楚。你會碰巧知道一個很好的方法來驗證跨越多個頁面的模型嗎?我認爲我可以創建類似於保存,創建,更新等的自定義方法,然後使用它來指定驗證是否處於活動狀態,但我認爲我現在瞭解其差異。 – Jeff 2010-01-29 16:27:35

1

它看起來像你想要一個嚮導插件。這兩個我所知道的是:

  1. acts_as_wizard
  2. wizardly

希望這些應該讓你開始。

相關問題