Ruby on rails 简单表格&;引导验证不起作用
我想设置一个“创建帐户”页面。我使用的宝石有:Ruby on rails 简单表格&;引导验证不起作用,ruby-on-rails,twitter-bootstrap,omniauth,simple-form,Ruby On Rails,Twitter Bootstrap,Omniauth,Simple Form,我想设置一个“创建帐户”页面。我使用的宝石有: 轨道(3.2.3) 简易表格(2.0.1) omniauth身份 twitter引导程序rails(2.0.6) mongoid(2.2.3) 表格如下: = simple_form_for @identity, :url => '/auth/identity/register', :html => { :class => 'form-horizontal' } do |f| = f.input :name, :i
- 轨道(3.2.3)
- 简易表格(2.0.1)
- omniauth身份
- twitter引导程序rails(2.0.6)
- mongoid(2.2.3)
= simple_form_for @identity, :url => '/auth/identity/register', :html => { :class => 'form-horizontal' } do |f|
= f.input :name, :input_html => {:name => 'name'}
= f.input :email, :input_html => {:name => 'email'}
= f.input :password, :as => 'password', :input_html => {:name => 'password'}
= f.input :password_confirmation, :label => "Confirm Password", :as => 'password', :input_html => {:name => 'password_confirmation'}
.form-actions
= f.button :submit, 'Sign Up', class: 'btn-primary'
= link_to 'Cancel', root_path, class: 'btn-danger'
相应的身份模型是
class Identity
include Mongoid::Document
include OmniAuth::Identity::Models::Mongoid
field :name, :type => String
field :email, :type => String
field :password_digest, :type => String
validates_presence_of :name, :email
validates_uniqueness_of :email
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
end
如果我没有填写表单的任何文本字段,然后单击“注册”,表单不会显示来自验证程序的任何错误消息,而是将我重定向到主页
我是否遗漏了一些明显的东西,或者这可能是我使用的gem版本的一些问题?当然,我可以使用twitter引导标记实现相同的表单,而不使用简单的表单,但我更喜欢这种方式 我遇到了类似的情况,simple_form确实验证了另一个模型中的字段,但没有验证用户模型中的字段 无论如何,我注意到你没有:
validates_presence_of :password
在你的模型中。也许mongoid可以让你免于这一步?我不知道mongoid,但对我来说,这就是验证字段不是空白的魔力。对于为我工作的领域,我有:
validates_presence_of :title, :localeLanguage, :message => "can't be blank"
我有这个问题,我通过在我所有的简单形式中包含它来修复它,然后我发现它正确地呈现:
<%= f.error_notification %>