无法包含用于客户端幻灯片验证的js文件 [英] Can't include js file for client slide validation

查看:68
本文介绍了无法包含用于客户端幻灯片验证的js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了gem'client_side_validations',运行包并运行rails g client_side_validations:install

安装DIDN"T会创建任何js文件,因此我创建了它们,并将HitHub中的代码放在我的asset/javascript文件夹中.

将行添加到application.js

I installed gem 'client_side_validations', run bundle and run rails g client_side_validations:install

Installation DIDN"T create any js files, so I created them and put code from HitHub in my assets/javascript folder.

added line into application.js

  //= require rails.validations  

将行添加到application.html.erb

added line into application.html.erb

       <%= javascript_include_tag :defaults, "rails.validations", "rails.validations.custom" %>

并且验证无法在线进行(使用Devise gem)

我认为:

and validation isn't working online(using Devise gem)

In my view:

 <%= form_for resource, ... , :validate => true do |f| %>

在GoogleChrome控制台日志中:

In GoogleChrome console logs:

   Failed to load resource: the server responded with a status of 404 (Not Found)
"/assets/javascripts/rails.validations.custom.js"
"/assets/javascripts/rails.validations.js"

我错过了什么?

推荐答案

当您运行命令rails g client_side_validations:install时,它似乎仅生成初始化程序config/initializers/client_side_validations.rb.

When you run the command rails g client_side_validations:install it seems to only generate the initializer config/initializers/client_side_validations.rb.

但是,在 github页面上,他们提到了用于复制javascript的命令文件保存到项目的资产:rails g client_side_validations:copy_assets

However, on the github page under the "Install" section they mention the command for copying the javascript file to the project's assets: rails g client_side_validations:copy_assets

注意::如果您运行Rails> = 3.1,则不再需要在布局中添加javascript文件,只要application.js只要具有<%= javascript_include_tag "application" %>就足够了包含//= require_tree .行,其中包括app/assets/javascripts目录下的所有javascript文件.

Note: If you run Rails >= 3.1 you don't need to add the javascript file in the layout anymore, it should be sufficient to have <%= javascript_include_tag "application" %> as long as the application.js contains the line //= require_tree . which includes all javascript files under app/assets/javascripts directory.

在初始化程序client_side_validations.rb文件中,您还需要取消注释最后一个块:

In the initializer client_side_validations.rb file you also need to uncomment the last block:

# 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|
  ...
end

完成此操作后,您需要重新启动服务器以使更改生效.

Once you have done this you need to restart the server for the changes to take effect.

这篇关于无法包含用于客户端幻灯片验证的js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆