我正在将我的Rails 3.1应用程序与jQuery mobile(Beta 2,目前)集成,我不确定如何组织我的JS和CSS.
我在我的application.mobile.erb的head标签中有这个(从http://jquerymobile.com/download/复制):
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
我应该把我的stylesheet_link_tag用于'应用程序',因此我的CSS样式不会覆盖jQuery mobile的花哨CSS吗?"应用程序"的javascript_include_tag怎么样?
或者所有这些都应该完全分开?
我只是不确定如何组织所有这些/如果有传统的方法来做到这一点.投入赞赏.
(如果您需要,请询问更多详情.)
编辑:*我也想知道在哪里放置我的移动专用JS和CSS ...
mobile ruby-on-rails jquery-mobile ruby-on-rails-3.1 asset-pipeline
刚刚开始适应rails 3.1,我开始编写coffeescript和sass,一切都在开发中运行良好.当我在生产中运行服务器时,我只得到:
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/javascripts/application.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
在页面的源代码中,没有生成哈希码,并且两个资产都有路由错误:
Routing Error
No route matches [GET] "/stylesheets/application.css"
Run Code Online (Sandbox Code Playgroud)
这是什么原因?我忘记做某事吗?
环境/ production.rb中的设置:
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# 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 …Run Code Online (Sandbox Code Playgroud) 我的Mailer模板中的视图助手为我提供了样式表和图像的相对URL.当然,如果我在Gmail中查看电子邮件,这将无效.
在 apps/views/layouts/mailer.html.erb
<%= stylesheet_link_tag "application" %>
...
<%= link_to(image_tag("logo.png"), "http://mysite.com") %>
Run Code Online (Sandbox Code Playgroud)
呈现为:
<link href="/assets/application-c90478153616a4165babd8cc6f4a28de.css" media="screen" rel="stylesheet" type="text/css" />
...
<a href="http://mysite.com"><img alt="Logo" src="/assets/logo-d3adbf8d0a7f7b6473e2130838635fed.png" /></a>
Run Code Online (Sandbox Code Playgroud)
我如何让Rails给我绝对链接呢?我在Rails 3.1上,资产管道生效.
我目前有一个Rails 3.1应用程序,可以为多个不同的客户托管多个站点.每个站点都由一个模型表示,该模型知道域名和存储资产的路径,以及其他一些信息.
我一直app/sites/domain-name用作存储特定于某个站点的资产,视图和语言环境的位置,并且正在运行自定义中间件和控制器操作,用于修改Sprockets的加载路径,设置视图路径等等.
中间件(使用config.middleware.use "Configurator"in 加载application.rb):
class Configurator
def initialize(app)
@app = app
end
def call(env)
@env = env
clear_existing_paths
prepend_local_assets
@app.call(env)
end
def current_site
# find site using @env
end
def current_site_path
Rails.root.join('app', 'sites', current_site.path)
end
def clear_existing_paths
paths = Rails.application.assets.paths
Rails.application.assets.clear_paths
paths.each do |path|
next if path.include?("app/sites/")
Rails.application.assets.append_path path
end
end
def prepend_local_assets
path = current_site_path.join('assets')
return unless Dir.exists?(path)
['images', 'javascripts', 'misc', 'stylesheets'].each do |subdir|
asset_dir = path.join(subdir).to_s
next unless Dir.exists?(asset_dir)
next …Run Code Online (Sandbox Code Playgroud) 我的问题类似于这个带有乘客无尽错误的Rails 3.2资产管道,除了当我尝试实际去的时候
<link href="/assets/application-eed7996ee9017637f923133371ab3e92.css" media="all" rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)
我得到了404.这是我不明白的事情.它正在查看/ assets /,但是当我查看部署的代码时,资产只在/ public/assets中,这实际上是/ var/www/myapp/shared/assets的符号链接.那么世界上有什么责任告诉应用程序,查看/资产会产生正确的结果?
我正在使用Rails 3.2.0,ruby-1.9.3-p125,部署到Ubuntu,Apache和Thin.
我应该澄清一下:我的资产确实已部署到服务器上.一切都很好,直到他们需要服务,在这种情况下,production.log告诉我它正在/assets/application-eed7996ee9017637f923133371ab3e92.css中寻找它们,这是404的.
对于每个请求,我的thin.log说
cache: [GET /] miss
Run Code Online (Sandbox Code Playgroud)
和production.log说
ActionController::RoutingError (No route matches [GET] "/assets/application-abecf2e096af9ee80697fd49e79a55e7.js"):
Run Code Online (Sandbox Code Playgroud)
更新
@Brandan感谢您的帮助.我的资产确实在RAILS_ROOT/public/assets.我把它放在我的Apache vhost文件中:
DocumentRoot /var/rails/myappname/current/public
RewriteEngine On
XSendFile On
XSendFilePath /var/rails/myappname #not even sure if this line is needed
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
Run Code Online (Sandbox Code Playgroud)
我的RAILS_ROOT/config/environments/production.rb设置:
config.cache_classes = true
config.consider_all_requests_local = false …Run Code Online (Sandbox Code Playgroud) 问题
我有一个Rails 3.0.4应用程序,我按照Railscast视频的说明升级到3.1.4 :"升级到rails 3.1".
现在我遇到资产问题,因为它们没有解决,在服务器日志中给出消息,如下所示:
Started GET "/assets/application.css" for 127.0.0.1 at 2012-04-08 03:57:13 -0500
Served asset /application.css - 404 Not Found (15ms)
ActionController::RoutingError (No route matches [GET] "/assets/application.css"):
Rendered /usr/local/rvm/gems/ruby-1.9.2-p318/gems/actionpack-3.1.4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (14.3ms)
Started GET "/assets/application.js" for 127.0.0.1 at 2012-04-08 03:57:13 -0500
Served asset /application.js - 404 Not Found (35ms)
ActionController::RoutingError (No route matches [GET] "/assets/application.js"):
Run Code Online (Sandbox Code Playgroud)
这些文件在assets目录中:
$ ls app/assets/*/application*
app/assets/javascripts/application.js app/assets/stylesheets/application.css
Run Code Online (Sandbox Code Playgroud)
并包含这个:
$ cat app/assets/javascripts/application.js
//= require jquery
//= …Run Code Online (Sandbox Code Playgroud) 我正在使用AngularJS和Rails构建一个网站.我用于模板的HTML文件存储在/ app/assets/templates下,每次更新路径或更改模板内部嵌套部分内的内容时,我都需要"触摸"最高级别的文件.我正在改变的html文件的/ app/assets/templates目录.
因此,如果我有一个页面"edit.html"加载部分"_form.html",那么每当我更新路线或更改_form.html中的内容时,我都需要确保触及edit.html.
这很烦人,非常挑剔.有没有办法通知资产管道/链轮,以避免app/assets/templates目录的缓存?
好的,所以编译我的资产工作正常,但当我运行时:
thin start -e production
我的javascript或css都没有加载.我的浏览器也取消了获取资产的请求.我不确定为什么会这样,但我怀疑它是因为它认为它是404'.如果您查看顶部图像,您将看到我的application.css文件已编译并存储在我的assets文件夹中,但当我尝试访问该文件时,我收到了我的404.html文件.
是什么赋予了!?


编辑:
我被要求发表我的观点.以下是项目中的一些代码:
<% content_for :title, 'Quick Quote' %>
<% content_for :subtotal, get_subtotal %>
<% content_for :stylesheet_includes do %>
<%= stylesheet_link_tag "quote", "jquery-ui-timepicker-addon" %>
<% end %>
<% if @quote.errors.any? %>
<div class="flash alert">
<% @quote.errors.full_messages.each do |msg| %>
<div><%= msg %></div>
<% end %>
</div>
<% end %>
<h1>Quick Quote</h1>
Run Code Online (Sandbox Code Playgroud)
我的布局:
<!DOCTYPE html>
<html>
<head>
<title><%= (yield(:title) + " - " unless yield(:title).blank?).to_s + "Online Scheduler Order Taker" %></title>
<%= stylesheet_link_tag "application", "jquery-ui-timepicker-addon.css", …Run Code Online (Sandbox Code Playgroud) 在Rails 3,作为使用资产从管道default_url中carrierwave的上传,你不喜欢的东西如下:
class MyUploader
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
def default_url
# For Rails 3.1+ asset pipeline compatibility:
asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
end
end
Run Code Online (Sandbox Code Playgroud)
在导轨4中,管道被抽象到sprockets-rails gem/railtie中,因此上面的内容将为您提供:
未初始化的常量链轮::助手
看看sprockets-rails gem,替换助手似乎就是这样Sprockets::Rails::Helper.但是包含这个模块,asset_path("fallback/default.png")返回,简单地说:
# wrong:
"/fallback/default.png"
Run Code Online (Sandbox Code Playgroud)
不是我期望的资产和摘要感知网址:
"/assets/fallback/default-b3beee1588afe2ae582c64888cd007db.png"
Run Code Online (Sandbox Code Playgroud)
如何asset_path在视图外获得正确的行为?
我在Ruby on Rails 4应用程序中使用galetahub/ckeditor gem(版本4.0.6).我按照自述文件中的指南进行操作,但是当我//= require ckeditor/override在application.js文件中添加清单语句时,我收到以下错误:
Sprockets::FileNotFound - couldn't find file 'ckeditor/override'
Run Code Online (Sandbox Code Playgroud)
我的application.js档案是:
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require jquery.ui.all
//= require turbolinks
//
//= require ckeditor/override
//= require ckeditor/init
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
注意:由于我不需要使用上传功能,因此我跳过" 如何为商店上传文件生成模型 "中的说明.
我Gemfile是:
gem 'rails', '4.0.1.rc1'
...
gem 'turbolinks'
gem 'jquery-turbolinks', :git => 'https://github.com/kossnocorp/jquery.turbolinks.git'
gem 'ckeditor'
...
Run Code Online (Sandbox Code Playgroud) ruby-on-rails ckeditor sprockets asset-pipeline ruby-on-rails-4
asset-pipeline ×10
apache ×1
carrierwave ×1
ckeditor ×1
helper ×1
mobile ×1
sprockets ×1
thin ×1