如何在Rails 3中验证非模型表单? [英] How do I validate a non-model form in Rails 3?
问题描述
用于Login:Class的未定义方法`model_name'。
有什么想法?
使用Rails 3,你可以使用诸如Validations等一些
ActiveModel扩展来扩展普通旧Ruby对象。ActiveRecord是ActiveModel的扩展,支持DB。这里有一个很好的Railscast,用简单的例子来描述它:
在Rails 3中,Active Record的非数据库
功能是
被提取到主动模型中。这
允许您干净地添加验证
和其他功能无表
模型。 http://railscasts.com/episodes/219-active-model
Let's say I have a search form and I want to validate the length of the keyword. I want the form to highlight the invalid field (like model forms). I've looked everywhere and can't seem to find any useful information on validating non-model-backed forms in Rails 3. I've tried the validatable gem, but this doesn't seem to work with Rails 3:
undefined method `model_name' for Login:Class.
Any ideas?
With Rails 3 you can extend "plain old Ruby objects" with some ActiveModel extensions like Validations etc. ActiveRecord is extension of ActiveModel with DB support. Here is a very good Railscast describing it with easy example:
In Rails 3 the non-database functionality of Active Record is extracted out into Active Model. This allows you to cleanly add validations and other features to tableless models. http://railscasts.com/episodes/219-active-model
这篇关于如何在Rails 3中验证非模型表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!