0

に追加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_assetsrails.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 %>

問題が宝石ではなく、構成または構文にあることを願っています。

どんな洞察も十分に高く評価されます。

4

2 に答える 2

1

3-2-stableGemfile で使用し、 bundle install を実行します

gem 'client_side_validations', :github => 'bcardarella/client_side_validations', :branch => '3-2-stable'
于 2013-06-27T17:01:48.363 に答える
0

あなたの設定は問題ないように思います。フォームに「error_messages」クラスがありません。私は自分のプロジェクトで同じ検証を行いました。私のコードは次のとおりです。

<%= f.error_messages :header_message => "oops! you missed something",
  :message => "",
  :header_tag => :h3, :class => "background-color:#d24d33; color:#ffffff" %>

上記のコードをフォームにカスタマイズして配置します。エラーを表示する場所と方法を指定する必要があります。これはすべて上記のコードで定義されています。さらにサポートが必要な場合はお知らせください。

于 2013-06-27T16:53:18.693 に答える