Roh*_*wal 6 jquery ruby-on-rails jquery-plugins production-environment ruby-on-rails-3.2
我在生产服务器中遇到问题.这是另一个问题的重复,但所有问题 - 答案对我来说都不起作用.
我对'link_to'标签使用了'删除'方法: -
<%= link_to "Delete Campaign", campaign_path(campaign), :class => "btn btn-danger", :method => :delete, :confirm => 'Are you sure?'%>
Run Code Online (Sandbox Code Playgroud)
当我点击"删除广告系列"链接时,我会收到两次确认弹出窗口.这只发生在客户的生产环境中.
使用Ruby 1.9.2和Rails 3.2.13.
在我的gemfile中,我用过: -
gem 'jquery-rails'
Run Code Online (Sandbox Code Playgroud)
在我的application.js中: -
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-timepicker
//= require_tree ../../../vendor/assets/javascripts/
Run Code Online (Sandbox Code Playgroud)
在我的application.html.erb中: -
<%= javascript_include_tag "application" %>
<%= javascript_include_tag "http://code.jquery.com/ui/1.10.2/jquery-ui.js" %>
Run Code Online (Sandbox Code Playgroud)
当我搜索它时,我发现: -
1. config.assets.debug在production.rb中应为false(它是假的但不起作用)
2.应该没有公共/资产目录(应用程序中没有这样的目录)
3运行rake资产:清理生产(无效果)
4.应从application.js中删除这两行: -
// = require jquery
// = require jquery_ujs
最后一个为我工作,但删除这些行后,整个应用程序受到影响,所有jquery事件停止工作.
根据我的知识,jquery加载两次(但使用的javascript_include_tag不超过一个)或者"config.assets.compile"中存在问题,这在production.rb中是正确的.
我无法在我的本地和heroku上检查它,因为它对两者都很好.
我的供应商/资产/ javascripts中的文件列表: -
我在开发环境(Rails 3.2.13)中遇到了同样的问题。我正在使用以下 gem 版本(来自 Gemfile.lock):bootstrap-sass (2.3.1.0)、sass-rails (3.2.6)、jquery-rails (2.2.1)。在 app/assets/javascripts/application.js 中:
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree
Run Code Online (Sandbox Code Playgroud)
在application.html.erb中:
<%= javascript_include_tag "application" %>
Run Code Online (Sandbox Code Playgroud)
在我的 erb 模板中:
<%= button_to 'Delete', @card_type, method: :delete, form_class: 'destroy_button',
data: { confirm: "Are you sure?" } %>
Run Code Online (Sandbox Code Playgroud)
看来 input[data-confirm] 的处理程序被添加了两次,一次是通过要求 jquery_ujs,另一次是通过要求 bootstrap。我通过不需要 jquery-ujs 消除了确认警报的双重触发,但我希望其他人发布更令人满意的解决方案。