2
votes

I want to setup a 'Create Account' page. The gems I'm using are:

  • rails (3.2.3)
  • simple_form (2.0.1)
  • omniauth-identity
  • twitter-bootstrap-rails (2.0.6)
  • mongoid (2.2.3)

The form looks as follows:

= 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'

The corresponding Identity model is

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

If I don't fill in any of the text field of the form and then click on 'Sign Up', the form does not display any error messages from the validators, but instead redirects me to the home page!

Am I missing something obvious or could this be some problem with the gem versions I am using? I could of course implement the same form without simple_form using twitter-bootstrap markup, but would prefer it this way.

2

2 Answers

1
votes

I'm in a similar situation where simple_form does validate a field in another model, but not in the user model.

In any case, I noticed you don't have:

validates_presence_of :password

in your model. Maybe mongoid saves you from doing that step? I don't know mongoid, but for me that is the magic that validates that the field is not blank. For the field that is working for me I have this:

validates_presence_of :title, :localeLanguage, :message => "can't be blank"
1
votes

I had this problem, I fixed it by including this in all my simple forms, I then find that it renders properly:

<%= f.error_notification %>