I have application rails and use client_side_validations gem with Devise to validate devise registrations form
//account.rb
has_one :user
validates :username, presence: true, uniqueness: true
//user.rb
belongs_to :account
validates :email, presence: true, uniqueness: true
//new.html.erb
<%= form_for(@user, :url => registration_path(resource_name), :validate => true) do |f| %>
<%= f.fields_for :account, :validate => true do |inner_form|%>
<div class="field">
<%= inner_form.label :username, "Username" %><br />
<%= inner_form.text_field :username %>
</div>
<% end %>
<div class="field">
<%= f.label :email, "Email" %>
<%= f.email_field :email %>
</div>
<div>
<%= f.submit "Sign up" %>
</div>
<% end %>
Validations work fine with email field but for username not worked.. help me,,, thanks
UPDATE ---validate show but this is no nested form
change :account to @account
<%= f.fields_for :account, :validate => true do |inner_form|%>
to
<%= f.fields_for @account, :validate => true do |inner_form|%>
when submit i get the error Account(#27129348) expected, got ActiveSupport::HashWithIndifferentAccess(#26695068)
when validates not worked, html code
<input id="user_account_attributes_username" name="user[account_attributes][username]" size="30" type="text" data-validate="true">
validates worked
<input id="user_account_username" name="user[account][username]" size="30" type="text" data-validate="true">
issue
user_account_attributes_username
user[account_attributes][username]
worked
user_account_username
user[account][username]
<%= f.fields_for :account. I am certain that you should have it set out like the following<%= fields_for @account, :validate => true do |inner_form|%>let me know if this resolves the issue. - user532339