简体   繁体   English

link_to没有反应:confirm =>

[英]link_to does not react to :confirm =>

I did search for two days now to find out why this seemingly simple piece of javascript does not work in my Ruby on Rails app. 我确实搜索了两天,以找出为什么这个看似简单的javascript不能在我的Ruby on Rails应用程序中运行。 I have the following code: 我有以下代码:

<%= link_to "+ nieuw verzoek", :controller => "tickets", :action => "new", :confirm => "are you sure ?" %>

The link works but without showing me the a popup-screen with the confirm question. 该链接有效,但没有向我显示带有确认问题的弹出屏幕。 And I don't know why. 而且我不知道为什么。

Here is some info about my app files: 以下是有关我的应用程序文件的一些信息:

My Gemfile:
-------------

source 'https://rubygems.org'

gem 'rails', '3.2.8'
gem 'bcrypt-ruby', '3.0.1'


group :assets do
gem 'sass-rails',   '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'


group :development do
gem 'pg', '0.12.2'
gem 'annotate'
#gem 'sqlite3', '1.3.5'
end

group :production do
gem 'pg', '0.12.2'
end
------end gemfile-----

---------------
software versions
---------------
Rails 3.2.8
ruby 1.9.3p362
---------------

-------------------
application.js
-------------------
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
---------------------

----------------------
application.html.erb
----------------------

<head>
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Cantarell' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Old+Standard+TT' rel='stylesheet' type='text/css'>
<title>SimpleCms</title>
<%= stylesheet_link_tag    "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>

</head>

-----------------------

Jquery does work. jQuery确实有效。 When I create a simple: 当我创建一个简单的:

<div> <a class="jq" href="#"> test </a></div> 

or by using this: 或使用以下方法:

<%= link_to "test",{}, :href => "#",:class => "jq" %>

I am able to manipulate the content of this class via Jquery code. 我可以通过Jquery代码操纵此类的内容。

$(document).ready(function() {
$('.jq').click(function() {
$('.jq').animate(
{
fontSize: '40px'    
},
5000 
);

});
});

But when I genereate a link via link_to like this: 但是当我像这样通过link_to生成链接时:

<%= link_to "+ nieuw verzoek", :controller => "tickets", :action => "new", :confirm => "are you sure ?" %>

No javascript is coming into action. 没有javascript生效。

Hope someone can give me some direction in solving my small problem. 希望有人能给我一些指导,以解决我的小问题。

Thanks! 谢谢!

你可以这样

<%= link_to "+ nieuw verzoek", {:controller => "tickets", :action => "new"}, :confirm => "are you sure ?" %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM