mar*_*ion 5 heroku client-side-validation devise ruby-on-rails-3
这是我的User
模特:
class User < ActiveRecord::Base
rolify
devise :database_authenticatable, :registerable, :token_authenticatable, :confirmable, :timeoutable,
:recoverable, :rememberable, :trackable, :validatable,
:email_regexp => /^([^@\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 => false
validates_confirmation_of :password
end
Run Code Online (Sandbox Code Playgroud)
的Gemfile:
gem 'client_side_validations'
形成:
<%= form_for(resource, :as => resource_name, :class => "send-with-ajax", :url => user_registration_path(resource), :validate => true, :html => { :id => 'user_new' }) do |f| %>
<%= f.text_field :email,:placeholder => "your-email@address.com", :input_html => {:autofocus => true}, :validate => true %>
<%= f.submit :label => "Submit", :value => "Sign Me Up!" %>
<div class="ajax-response"><%= devise_error_messages! %></div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
当你跳出字段时它应该工作,这是它在本地工作的截图:
但是当我在生产中这样做时,它根本不起作用,我没有在日志文件或JS控制台中看到任何错误.
编辑1:
验证消息未显示.
在Heroku日志中,每当我尝试"有效"的电子邮件地址时,我都会看到这一点:
2012-06-10T18:44:55+00:00 app[web.1]: Started GET "/validators/uniqueness?case_sensitive=false&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&user%5Bemail%5D=abc%40tell.com dyno=web.1 queue=0 wait=0ms service=221ms status=404 bytes=4
Run Code Online (Sandbox Code Playgroud)
但它并没有像我在本地那样向我显示我的页面上的消息.
此外,我在日志中看到HTTP请求的唯一一次是当我尝试具有"有效"电子邮件结构的字符串时 - 就像abc@email.com
.但是,如果我尝试类似的东西,abc
它不会给我我期望的信息 - invalid address
- 日志也没有显示任何内容.
编辑2:
我尝试运行我的本地服务器production mode
,我看到了与Heroku相同的问题.所以似乎问题可能与Heroku无关 - 而是生产.
这是从生产中的表单生成的HTML:
<form accept-charset="UTF-8" action="/users" class="formtastic user" data-validate="true" id="user_new" method="post" novalidate="novalidate"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="kQid^%&^%jhgdsjhgfxmw4=" />
<input data-validate="true" id="user_email" input_html="{:autofocus=>true}" name="user[email]" placeholder="your-email@address.com" size="30" type="text" />
<input label="Submit" name="commit" type="submit" value="Sign Me Up!" />
</form><script>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}}}};</script> </div>
Run Code Online (Sandbox Code Playgroud)
编辑3:
这就是我的application.js的样子:
//= require jquery
//= require jquery_ujs
//= require rails.validations
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
在我的application.html.erb
布局文件中,我只是对application.js进行了JS调用
编辑4:
我认为可能client_side_validation
是由于生成的JS脚本没有识别输入,因为id是user_email
和不是user[email]
.所以我改变了id
输入user[email]
,并没有解决它.
有人有什么想法?
最好的猜测是,这会追踪到资产管道。其他一些 gem 可能会阻止资产正确编译。
我没有给你一个完美的答案,但 Heroku 文档可能会有所帮助: https: //devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar
归档时间: |
|
查看次数: |
1644 次 |
最近记录: |