我现在搜索了两天,以找出为什么这个看似简单的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开始行动。
希望有人可以帮我解决我的小问题。
谢谢!
答案 0 :(得分:1)
你可以这样做
<%= link_to "+ nieuw verzoek", {:controller => "tickets", :action => "new"}, :confirm => "are you sure ?" %>