に追加client-side-validations
してGemfile
実行しましbundle install
た。それから走ったrails g client_side_validations:install
作成されましたconfig/initializers/client_side_validations.rb
(私の JS ファイルはどこですか? アセット パイプラインは?)
ボックスでうまくいくはずですが、うまくいかなかったようです。
にconfig/initializers/client_side_validations.rb
アクセスして、次の行のコメントを外しました。
#ClientSideValidations Initializer
# Uncomment to disable uniqueness validator, possible security issue
# ClientSideValidations::Config.disabled_validators = [:uniqueness]
# Uncomment the following block if you want each input field to have the validation messages attached.
# ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
# unless html_tag =~ /^<label/
# %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
# else
# %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
# end
# end
に:
#ClientSideValidations Initializer
# Uncomment to disable uniqueness validator, possible security issue
# ClientSideValidations::Config.disabled_validators = [:uniqueness]
# Uncomment the following block if you want each input field to have the validation messages attached.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
unless html_tag =~ /^<label/
%{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
else
%{<div class="field_with_errors">#{html_tag}</div>}.html_safe
end
end
私は実行することに決めたので、自分のファイルにrails g client_side_validations:copy_assets
rails.validations ( //= require rails.validations
)を要求しました ( の前に)。application.js
//= require tree .
フォーム フィールドの外にタブで移動しようとしてもインライン エラーは表示されず、フォームを送信してもエラーは表示されません。
フォームとモデルに次のコードがあります。
class User < ActiveRecord::Base
has_secure_password
attr_accessible :email, :password, :password_confirmation
validates_presence_of :email
validates_presence_of :password, :on => :create
validates_length_of :password, :minimum => 6
validates_confirmation_of :password
validates_uniqueness_of :email
end
<h1>Sign Up</h1>
<%= form_for User.new, :validate => true do |f| %>
<p>
<%= f.label :email %>
<%= f.text_field :email %>
</p>
<p>
<%= f.label :password %>
<%= f.password_field :password %>
</p>
<p>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
</p>
<p>
<%= f.submit "Sign Up" %>
</p>
<% end %>
問題が宝石ではなく、構成または構文にあることを願っています。
どんな洞察も十分に高く評価されます。