- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有使用 Rails 3.2.6 和 Ruby 1.9.3p0 版本的 Rails 应用程序。我的 Assets 文件夹中有许多 CSS 和 JS(使用 JQuery)文件和 Assets 管道。一切正常,但我从 切换从开发到生产,压缩到名为 application.css 和 application.js 的单个文件,然后我的大部分JQuery 代码都不起作用。我已经尝试了许多现有的解决方案,但没有任何帮助。
请帮助。提前致谢。
这是我的 application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Tritinum <%#= controller.action_name %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery- ui.min.js", "jquery.rails.js" %>
<%= stylesheet_link_tag 'http://fonts.googleapis.com/css?family=Droid+Sans:400,700'%>
<%= csrf_meta_tags %>
</head>
<body>
<!-- BEGIN MAIN -->
<section id="main" class="container_16">
<p class="notice"><%#= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
<!-- BEGIN FOOTER -->
<section class="footer">
<p>
<span class="left">�Copyright 2012 - All rights reserved. </span>
<span class="right">Web Tool v1.0 - Product By<a href="http://www.google.com">Personal.</a></span>
</p>
<div class="clear"></div><!-- CLEAR BOTH -->
</section><!-- end section .footer -->
<!-- END FOOTER -->
</section><!-- end section #main -->
<!-- END MAIN -->
<!-- BEGIN LOADING OVERLAY -->
<div id="loading_overlay">
<div class="loading_message round_bottom">
<%= image_tag "loading.gif" %>
</div>
</div>
<!-- END LOADING OVERLAY -->
</body>
</html>
应用.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Tritinum
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.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# 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
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
config.assets.initialize_on_precompile = false
# config.assets.precompile = ['*.css']
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end
生产.rb
Tritinum::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# C hoose the compressors to use
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :yui
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = false
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to Rails.root.join("public/assets")
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end
同时,我在使用此命令编译后在生产环境中启动 Rails 服务器
RAILS_ENV=production bundle exec rake assets:precompile
我的大部分 JQuery 代码都停止工作了。
gem 文件
source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'haml'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'wkhtmltopdf-binary'
gem 'sqlite3'
gem 'devise'
gem 'cancan'
gem 'faker'
gem 'rb-readline'
gem 'paperclip'
gem 'wicked_pdf'
gem "nested_form", :git => 'https://github.com/ryanb/nested_form.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platform => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
app/assets/javascripts/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_nested_form
//= require jquery
//= require jquery_ujs
//= require_tree .
function remove_fields(link) {
$(link).previous("input[type=hidden]").value = "1";
$(link).up(".fields").hide();
}
$(document).ready(function(){
$("select#finding_category_id").change(function(){
var id_value_string = $(this).val();
if (id_value_string == "") {
// if the id is empty remove all the sub_selection options from being selectable and do not do any ajax
$("select#finding_finding_template_id option").remove();
var row = "<option value=\"" + "" + "\">" + "" + "</option>";
$(row).appendTo("select#finding_finding_template_id");
}
else {
// Send the request and update sub category dropdown
$.ajax({
dataType: "json",
cache: false,
url: '/finding_templates/for_categoryid/' + id_value_string,
error: function(XMLHttpRequest, errorTextStatus, error){
alert("Failed to submit : "+ errorTextStatus+" ;"+error);
},
success: function(data){
// Clear all options from sub category select
$("select#finding_finding_template_id option").remove();
//put in a empty default line
var row = "<option value=\"" + "Select" + "\">" + "" + "</option>";
$(row).appendTo("select#finding_finding_template_id");
// Fill sub category select
$.each(data, function(i, j){
row = "<option value=\"" + j.finding_template.id + "\">" + j.finding_template.name + "</option>";
$(row).appendTo("select#finding_finding_template_id");
});
}
});
};
});
});
请别人帮忙
最佳答案
config.assets.initialize_on_precompile = false
^ application.rb
中的那一行是告诉预编译函数延迟预编译。这意味着它只会在您的主应用程序中预编译 Assets 。如果将此设置为 true,它将能够预编译其他引用的 Gem 中包含的 Assets 。因此,除非您在应用程序的 Assets 文件夹中显式 拥有 jquery
文件,否则它可能会在预编译时丢失 - 因此它不会包含在您的 应用程序中。 js
.
注意
这一行:config.assets.compile = true
应该告诉您的应用程序在缺少预编译 Assets 时回退到 Assets 管道 - 理想情况下这将意味着它将从普通管道中找到 jquery Assets 。
但是我的猜测是,由于技术上它确实找到了 application.js
,您的应用程序不知道有一个丢失的 Assets ,所以它加载预编译了 application.js
然后它就无法获取 jquery
代码。
解决方案
抱歉冗长的解释,但请尝试以下操作 - 在您的 config/application.rb
config.assets.initialize_on_precompile
为真
然后您当然必须重建和重新部署 :) 如果这有帮助请告诉我!!
关于jquery - 在 Rails 3.2.6 中从开发切换到生产,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11554694/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!