モデルユーザーがいます
class User < ActiveRecord::Base
validates :goal, :presence => true, :on => :update
belongs_to :goal, :class_name => Goal, :foreign_key => "goal_id"
...
end
そして私が持っているフォームで
<%= simple_form_for @users,:remote => true, :url => registration_path(resource_name), :html => { :method => :put, :multipart => true }, :validate => true do |f| %>
<%= f.association :goal,:label => "My overall goal is clearing", :input_html => {:class => 'goals'},:include_blank => true %>
ただし、Railsのクライアント側の検証では、関連付けの検証が取得されないため、目標の空白を埋めることができます。
Railsのクライアント側の検証gemは、単純なフォームの関連付けで機能しますか?
HTMLページで以下のスクリプトを取得しています
if (window.ClientSideValidations == undefined) window.ClientSideValidations = {};
if (window.ClientSideValidations.forms == undefined) window.ClientSideValidations.forms = {};
window.ClientSideValidations.forms['edit_user_14'] = {
"type": "SimpleForm::FormBuilder",
"error_class": "error",
"error_tag": "span",
"wrapper_error_class": "field_with_errors",
"wrapper_tag": "div",
"wrapper_class": "input",
"wrapper": "default",
"validators": {
"user[mobile_number]": {
"format": [{
"message": "should be 10 digits",
"with": /^\d{10}$/i
}]
},
"user[profile_pic]": {
"integrity": [{
"message": "translation missing: en.activerecord.errors.models.user.attributes.profile_pic.integrity"
}],
"processing": [{
"message": "translation missing: en.activerecord.errors.models.user.attributes.profile_pic.processing"
}],
"download": [{
"message": "translation missing: en.activerecord.errors.models.user.attributes.profile_pic.download"
}],
"format": [{
"message": "Wrong file format",
"with": /\.(gif|jpeg|jpg|png)$/i,
"allow_blank": true
}]
}
}
};