0

この一見単純な JavaScript が Ruby on Rails アプリで機能しない理由を見つけるために、2 日間検索を行いました。次のコードがあります。

<%= 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 に答える