I have these 2 models:
users
has_one :additional_data, :dependent => :destroy
accepts_nested_attributes_for :additional_data
additional_data
belongs_to :user
validates :skype, :presence => {:message => 'cannot be blank.'}
and form:
<%= form_for@user do |f| %>
<p>
<%= f.label :email %><br />
<%= f.text_field :email %>
</p>
<%= f.fields_for :additional_data do |ad| %>
<p>
<%= ad.label :skype, "Skype" %><br />
<%= ad.text_field :skype %>
</p>
<% end %>
<% end %>
If I send empty form, the message about missing Skype data is not displayed. What am I missing?
Also, I would like to ask you, if I can according value in variable in URL validate the additional_data.
By default, Rails won’t display inline errors.
You can either use a plugin like simple form which I recommend, or display the errors at the beginning of the form by iterating over
@user.errors.full_messages.