本文介绍了Rails - 如何链接到应用程序目录外的资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Rails 的新手.我安装了 Zurb 基金会前端框架,如下所述:http://www.zurb.com/article/814/yetify-your-rails-new-foundation-gem-and-

当我打开 app/assets/stylesheets/application.css 时,我发现了这个自动生成的代码:

/** 这是一个清单文件,将自动包含此目录中所有可用的样式表* 和任何子目录.您可以自由地向该文件添加应用程序范围的样式,它们将出现在* 编译文件的顶部,但通常最好为每个样式范围创建一个新文件.*= require_self*= 需要基础*= require_tree .*/

但是,在我看来这一行

不加载我创建的文件 zurb_foundation/app/assets/stylesheets/foundation/index.css:

找不到文件基础"(在/Users/migu/railsapps/maneki1/app/assets/stylesheets/application.css:6)

如何让它加载文件和我放在 zurb_foundation/app/assets/stylesheets/foundation/下的所有 CSS 文件?谢谢...

解决方案

在 Rails 从 zurb-foundation gem 中获取新资产之前,您需要重新启动网络服务器.重新启动后,它应该可以正常工作.

此外,您可以检查是否从 rails 控制台正确找到了 zurb-foundation 资产.在命令提示符下,输入rails c",然后输入Rails.application.config.assets.paths"(两个命令都减去引号).您应该会看到如下内容:

=> ["/Users/MYUSER/appPath/app/assets/images", "/Users/MYUSER/appPath/app/assets/javascripts", "/Users/MYUSER/appPath/app/assets/stylesheets", "/用户/MYUSER/appPath/vendor/assets/stylesheets", "/Users/MYUSER/.rvm/gems/ruby-1.9.3-p0/gems/jquery-rails-1.0.19/vendor/assets/javascripts", "/Users/MYUSER/.rvm/gems/ruby-1.9.3-p0/gems/zurb-foundation-2.1.0/vendor/assets/images", "/Users/MYUSER/.rvm/gems/ruby-1.9.3-p0/gems/zurb-foundation-2.1.0/vendor/assets/javascripts", "/Users/MYUSER/.rvm/gems/ruby-1.9.3-p0/gems/zurb-foundation-2.1.0/供应商/资产/样式表"]

请注意,您可能需要做一些额外的工作才能将资产部署到生产环境中.

I'm brand new to Rails. I installed the Zurb foundation front-end framework as described here: http://www.zurb.com/article/814/yetify-your-rails-new-foundation-gem-and-

When I open app/assets/stylesheets/application.css I find this auto-generated code:

/*
* This is a manifest file that'll automatically include all the stylesheets available in      this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require foundation
*= require_tree .
*/

However, this line in my view

<%= stylesheet_link_tag    "application" %>

does not load the file zurb_foundation/app/assets/stylesheets/foundation/index.css I created:

couldn't find file 'foundation'
(in /Users/migu/railsapps/maneki1/app/assets/stylesheets/application.css:6)

How can I make it load the file and all CSS files I put under zurb_foundation/app/assets/stylesheets/foundation/? Thanks...

解决方案

You will need to restart the webserver before Rails picks up the new assets from the zurb-foundation gem. Once restarted, it should just work.

Also, you can check the zurb-foundation assets are correctly found from the rails console. At the command prompt, enter "rails c", and then "Rails.application.config.assets.paths" (both commands minus the quotes). You should see something like:

=> ["/Users/MYUSER/appPath/app/assets/images", "/Users/MYUSER/appPath/app/assets/javascripts", "/Users/MYUSER/appPath/app/assets/stylesheets", "/Users/MYUSER/appPath/vendor/assets/stylesheets", "/Users/MYUSER/.rvm/gems/ruby-1.9.3-p0/gems/jquery-rails-1.0.19/vendor/assets/javascripts", "/Users/MYUSER/.rvm/gems/ruby-1.9.3-p0/gems/zurb-foundation-2.1.0/vendor/assets/images", "/Users/MYUSER/.rvm/gems/ruby-1.9.3-p0/gems/zurb-foundation-2.1.0/vendor/assets/javascripts", "/Users/MYUSER/.rvm/gems/ruby-1.9.3-p0/gems/zurb-foundation-2.1.0/vendor/assets/stylesheets"]

Note you might need to do some extra work to get the assets deployed on production.

这篇关于Rails - 如何链接到应用程序目录外的资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:32