【问题标题】:does rails 3.1 download jquery and jquery ui files if specified in the asset pipeline?如果在资产管道中指定,rails 3.1 会下载 jquery 和 jquery ui 文件吗?
【发布时间】:2012-08-11 21:27:12
【问题描述】:

如果在资产管道中指定,rails 3.1 是否会下载 jquery 和 jquery ui 文件? 我安装了 gems,我的 application.js 如下 我需要手动将 jquery 复制到管道中吗?

宝石文件:

source 'http://rubygems.org'

gem 'rails', '3.1.0'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
  gem 'jquery-rails'
  gem 'jquery-ui-rails'
end

#gem 'jquery-rails'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :test do
  # Pretty printed test output
  gem 'turn', :require => false
end

布局:

<!DOCTYPE html>
<html>
<head>
  <title>Depot31</title>
  <%= stylesheet_link_tag    "application" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>

应用程序.js

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_tree .

【问题讨论】:

    标签: jquery ruby-on-rails asset-pipeline


    【解决方案1】:

    如果您在 Gemfile 中添加以下行,资产管道会处理此问题:

    gem "jquery-rails"
    gem 'jquery-ui-rails'
    

    查看jquery-rails 和jquery-ui-rails 了解如何设置此宝石的更多信息

    【讨论】:

    • 我刚刚使用这些说明创建了一个脚手架应用程序,但出现“无法正常文件 jquery”错误
    • 请用您的 gemfile、布局文件和 application.js 更新您的帖子,然后我应该可以提供帮助
    • 在 application.js 中,您必须将 jquery-ui 替换为 jquery.ui.all,您还必须按照给定链接后面的说明设置 jquery-ui css 规则。但这不是导致您错误的原因。我认为您必须停止服务器,然后运行“捆绑安装”并再次启动服务器。
    • 还是同样的错误?当我尝试在未将提到的 gem 添加到 Gemfile 的情况下运行服务器时,我的应用程序出现此错误。我没有更多的好主意。也许尝试使用新版本的 Rails,3.1.0 太旧了,可能有问题。
    猜你喜欢
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    相关资源
    最近更新 更多