Rails 4 Stylesheets / Js / Images的资产管理

时间:2014-06-20 13:37:55

标签: javascript css ruby-on-rails image

我使用的是管理主题,它有10-15个CSS / JS文件和更多图像。

我想包含它们并在新模板admin.html.erb

中使用它们

enter image description here enter image description here

这是让他们保持文件夹完好无损的最佳方法。

我可以使用带有指令的application.css admin.css以外的其他清单文件吗?

这就是主题导入资产的方式

enter image description here

1 个答案:

答案 0 :(得分:1)

需要修复几件事情。首先,删除那个巨大的红色和蓝色斑点。其次,移动你的"字体"目录输出到您的资产目录。然后,弹出你的application.css并确保它看起来像这样:

/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* 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_tree .
*/

@font-face {
    font-family: 'FontAwesome';
    src: url('fontawesome.eot');
    src: url('fontawesome.eot?#iefix') format('embedded-opentype'), url('fontawesome.svg#fontawesome') format('svg'), url('fontawesome.woff') format('woff'), url('fontawesome.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

这样做会自动加载"样式表中的所有样式表"目录进入您的应用程序,并注册您的字体,以便CSS可以使用它。第三,弹出你的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
compiled file.

Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
about supported directives.

= require jquery
= require jquery_ujs
= require turbolinks
= require_tree .
*/

那" require_tree"语句正是在application.css中完成了同一语句所做的事情;将所有内容加载到应用程序现在,您可以在视图中调用JavaScripts!

希望这有帮助!