- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尽管我在控制系统和固件方面拥有近二十年的 C/C++ 经验,并且掌握了大量 shell 和 perl 脚本,但我对 Rails 和 Web 开发还是个新手。
如果不显式包含 jquery,我就无法让 jquery 工作,即使它位于 application.js list 中,而且我根本无法让任何单独的 Coffeescript 工作。
Ubuntu 14.04LTS、ruby 2.2.1p85、rails 4.2.0
application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
application.html.erb
<%= render "layouts/header" %>
<%= render "layouts/sidenav" %>
<%= yield %>
<%= render "layouts/footer" %>
_header.html.erb
<html>
<head>
<title>My Application Title</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'intranet' %>
<%= stylesheet_link_tag 'form' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="shortcut icon" href="favicon.ico" />
</head>
<body>
...
gem 文件
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Pagination gem
gem 'kaminari'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
配置/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Boe
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end
end
我构建了 27 个 Controller 和 View ,其中有 11 个 Controller 和 View ,它们都运行良好,只是直到昨天我才尝试过任何 javascript。我没有得到任何预期的行为,因此在我的“人员”索引 View 中添加了:
...
<script>
$(document).ready(function(){
alert("jQuery is running!");
});
</script>
...
检查 jQuery 是否正常工作。如果我添加 <%= javascript_include_tag 'jquery.js' %>
在 csrf_meta_tag 之前,我收到警报消息,但 CoffeeScript 和其余部分仍然无法工作。如果没有显式的 jquery include,我什么也得不到。
我看过很多很多关于此的帖子,但没有一个起作用。在我看来,application.js 中的 list 没有被读取和/或列出的模块不包括在内,除了在从一个页面移动到另一个页面时,turbolink 似乎可以通过浏览器上的网络面板正常工作。我删除了 Turbolink,它的行为非常不同。
我还尝试包含 jquery-turbolinks gem,尽管我很确定 jquery-rails gem 不需要它。但它也不适用于卸载涡轮链接,所以我不认为这是冲突。
感谢您的浏览。
最佳答案
为了解决这个问题,我创建了一个空白应用程序,只有一个“欢迎” Controller ,仅包含 jQuery 测试脚本,效果很好。
从裸应用程序树中的差异开始回溯,我发现另一个开发人员生成了一个空的 Coffeescript 文件:
app/assets/javascript/application.coffee
我删除了该文件,应用程序正常工作。库存 javascript_include_tag
现在读取 list 并包含各种 javascript 模块,包括 jQuery、jQuery-ujs 和 Turbolinks。
关于javascript - Rails 4 jQuery、javascript 和 CoffeeScript 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30383395/
我有以下 Coffeescript: $ -> $('#new_event').submit -> $.post( $(this).attr('acti
Coffeescript docs包含以下简介 String Interpolation, Block Strings, and Block Comments Ruby-style string in
如何获得类似于 HTML 的 target='_blank' 的行为在 CoffeeScript 里面? 到目前为止,我已经尝试过: window.location = "/site/#{pk}/go
array = [1,2,3,4] for num in array //do something num的值是多少在函数的其余部分?是否num得到范围到循环? 最佳答案 不,num不会被限制
Coffeescript 使用存在运算符来确定变量何时存在,并且在 coffeescript documentation 中它表明 something?将编译为 something !== undef
我一直在阅读一些关于 coffeescript 的继承模型的内容,我感觉自己正处于一场我真的不理解的意识形态辩论的边缘。所以,我会非常高兴地发现我只是以错误的方式做事。 基本上我正在做的是编写一组小部
这个问题在这里已经有了答案: How to iterate over the keys and values in an object in CoffeeScript? (4 个回答) 8年前关闭。
让我们定义这个简单的代码: class Foo @foo = 'blah' console.log(@foo) class Bar extends Foo constructor: ()
除了这些示例之外,我正在努力寻找任何好的 CoffeeScript 和模式匹配示例: {x, y} = sprite css = {opacity, fontFamily} 我在 Erlang 中使用
我想做一个 if 语句来检查一个对象是否是一个空对象。 空对象是指如果我执行 console.log(object) 它会打印出 {}。 我该怎么做呢? 最佳答案 myObject = {} if O
在 JS 中创建文字数组时: [{ name: 'david', value: 'blue' }, { name: 'harold', value: 'orange' }] 我能看到在 Coffees
我的问题类似于发布的 here .本质上我想读一个配置file.json看起来像这样: { "message": "Error in #{baseName} at #{directory}" }
如果我有一个类,则将多个参数传递给: class Foo constructor: (parameters) -> @bar = parameters.bar @moo = paramet
coffeescript中是否有 namespace 的内在支持? 适当的命名空间似乎确实可以帮助Coffeescript有所帮助,尽管我似乎无法找到任何迹象表明存在对此的支持。 最佳答案 既可以在自
我有一个具有一些jquery事件侦听器的coffeescript类。我想使用粗箭头=>以避免引用该类,但是我仍然需要引用通常与this一起使用的元素。如何同时使用两者? class PostForm
我要转换 console.log({ a: 'a' }, { b: 'b' }); 进入 CoffeeScript。我发现的唯一方法是 console.log a: 'a', b:
我真的很喜欢这个: var value = maxValue > minValue ? minValue : maxValue; Coffeescript 中是否有同样简洁的东西? 最佳答案 valu
我想在coffeescript中编写一个静态帮助器类。这可能吗? 类别: class Box2DUtility constructor: () -> drawWorld: (world, co
super 简单的coffeescript问题 circles = [] for coordinate, i in coordinates circles[i] = new MakeCircl
我在看this great video由 Jeremy 在 CoffeeScript 上发表。他解释说,CoffeeScript 的理想之一是让“一切都是表达式”。 CoffeeScript 离这个理
我是一名优秀的程序员,十分优秀!