2010-01-29 43 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

希望这些应该让你开始。

相关问题