0

我现在确实搜索了两天,以找出为什么这个看似简单的 javascript 在我的 Ruby on Rails 应用程序中不起作用。我有以下代码:

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

该链接有效,但没有向我显示带有确认问题的弹出屏幕。我不知道为什么。

以下是有关我的应用程序文件的一些信息:

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 确实有效。当我创建一个简单的:

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

或通过使用这个:

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

我可以通过 Jquery 代码来操作这个类的内容。

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

});
});

但是当我像这样通过 link_to 生成链接时:

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

没有 javascript 正在发挥作用。

希望有人能给我一些指导来解决我的小问题。

谢谢!

4

1 回答 1

1

你可以这样做

<%= link_to "+ nieuw verzoek", {:controller => "tickets", :action => "new"}, :confirm => "are you sure ?" %>
于 2013-02-28T10:45:40.473 回答