Note that there are some explanatory texts on larger screens.

plurals
  1. POClient Side Validations doesn't work in production, but works in development
    text
    copied!<p>This is my <code>User</code> model:</p> <pre><code>class User &lt; ActiveRecord::Base rolify devise :database_authenticatable, :registerable, :token_authenticatable, :confirmable, :timeoutable, :recoverable, :rememberable, :trackable, :validatable, :email_regexp =&gt; /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :confirmed_at, :confirmation_token validates_uniqueness_of :email, :case_sensitive =&gt; false validates_confirmation_of :password end </code></pre> <p>Gemfile:</p> <p><code>gem 'client_side_validations'</code></p> <p>Form:</p> <pre><code>&lt;%= form_for(resource, :as =&gt; resource_name, :class =&gt; "send-with-ajax", :url =&gt; user_registration_path(resource), :validate =&gt; true, :html =&gt; { :id =&gt; 'user_new' }) do |f| %&gt; &lt;%= f.text_field :email,:placeholder =&gt; "your-email@address.com", :input_html =&gt; {:autofocus =&gt; true}, :validate =&gt; true %&gt; &lt;%= f.submit :label =&gt; "Submit", :value =&gt; "Sign Me Up!" %&gt; &lt;div class="ajax-response"&gt;&lt;%= devise_error_messages! %&gt;&lt;/div&gt; &lt;% end %&gt; </code></pre> <p>It should work when you tab out of the field, here is a screenshot of it working locally:</p> <p><img src="https://i.stack.imgur.com/wPCeN.png" alt="client_side_validation local"></p> <p>But when I do it in production, it doesn't work at all and I don't see any errors in the log file or in the JS console.</p> <p><strong>Edit 1:</strong></p> <p>Validation messages are not showing up.</p> <p>In Heroku logs, I see this whenever I try a 'valid' email address:</p> <pre><code>2012-06-10T18:44:55+00:00 app[web.1]: Started GET "/validators/uniqueness?case_sensitive=false&amp;user%5Bemail%5D=abc%40tell.com" for xx.xxx.xx.x2 at 2012-06-10 18:44:55 +0000 2012-06-10T18:44:55+00:00 heroku[router]: GET myapp.heroku.com/validators/uniqueness?case_sensitive=false&amp;user%5Bemail%5D=abc%40tell.com dyno=web.1 queue=0 wait=0ms service=221ms status=404 bytes=4 </code></pre> <p>But it doesn't show me a message on my page like it does locally.</p> <p>Also, the only time I see that HTTP request in the log is when I try a string that has a 'valid' email structure - like <code>abc@email.com</code>. But if I try something like <code>abc</code> it doesn't give me the message I expect - <code>invalid address</code> - nor does the log show anything.</p> <p><strong>Edit 2:</strong></p> <p>I tried running my local server in <code>production mode</code> and I am seeing the same issue as on Heroku. So it seems the issue may not have anything to do with Heroku - but rather production.</p> <p>This is the HTML generated from the form in production:</p> <pre><code>&lt;form accept-charset="UTF-8" action="/users" class="formtastic user" data-validate="true" id="user_new" method="post" novalidate="novalidate"&gt;&lt;input name="utf8" type="hidden" value="&amp;#x2713;" /&gt;&lt;input name="authenticity_token" type="hidden" value="kQid^%&amp;^%jhgdsjhgfxmw4=" /&gt; &lt;input data-validate="true" id="user_email" input_html="{:autofocus=&amp;gt;true}" name="user[email]" placeholder="your-email@address.com" size="30" type="text" /&gt; &lt;input label="Submit" name="commit" type="submit" value="Sign Me Up!" /&gt; &lt;/form&gt;&lt;script&gt;window['user_new'] = {"type":"Formtastic::FormBuilder","inline_error_class":"inline-errors","validators":{"user[email]":{"presence":{"message":"can't be blank"},"uniqueness":{"message":"has already been taken","case_sensitive":false},"format":{"message":"is invalid","with":/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,"allow_blank":true}}}};&lt;/script&gt; &lt;/div&gt; </code></pre> <p><strong>Edit 3:</strong></p> <p>This is how my application.js looks:</p> <pre><code>//= require jquery //= require jquery_ujs //= require rails.validations //= require_tree . </code></pre> <p>And in my <code>application.html.erb</code> layout file I just have a JS call to application.js</p> <p><strong>Edit 4:</strong></p> <p>I thought it may have been a situation where the JS script generated by <code>client_side_validation</code> is not recognizing the input because the id is <code>user_email</code> and not <code>user[email]</code>. So I changed the <code>id</code> for the input to <code>user[email]</code> and that did not solve it.</p> <p>Anyone have any thoughts?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload