Rails - 命名空间 Css 不工作 [英] Rails -Namespace Css Not Working

查看:46
本文介绍了Rails - 命名空间 Css 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 Web 应用程序中实现一个管理命名空间.它在我的本地机器上运行良好但是当我尝试部署应用程序时,我的 css 都没有工作.我试过

I am trying to implement a admin namespace into my web application .It is working fine on my local machine but when I am trying to deploy the application none of my css is working. I tried

耙资产:预编译

我已经重新启动了服务器.我的结构看起来像这样

I have restarted the server .My structure looks like this

  • 应用

  • 资产

  • 样式表

.应用程序.css

  • 管理员

  • my_admin.css

与Javascripts相同的结构.在我使用的布局文件中

The same structure is with Javascripts.In my layout file I have used

 <%= stylesheet_link_tag    "admin/my_admin" %>
 <%= javascript_include_tag "admin/my_admin" %>

当我运行我的应用程序时,它工作正常,但我的 css 和 javascript 都不存在..在我的浏览器检查器中,它说 my_admin css 和 javascript not found.Any help??

When I run my application it works fine but none of my css nor javascript is there ..In my Browser inspector it is saying my_admin css and javascript not found.Any help??

推荐答案

在生产中你可能有

config.assets.compile = false

在您的 config/environment/production.rb 中.这可以防止资产管道像在开发中一样在生产中按需编译脚本.

in your config/environment/production.rb. This prevents the asset pipeline from compiling scripts on demand in production as it does in development.

您需要指定要预编译的任何 .js.css 资产,这些资产不是 application.jsapplication.css.

You need to specify any .js or .css assets you want precompiled which are not application.js or application.css.

将以下内容添加到您的 config/environment/production.rb

Adding the following to your config/environment/production.rb

config.assets.precompile += ["admin/my_admin.css", "admin/my_admin.js"] 

并运行 rake assets:precompile 应该将这些编译好的资源放入 public/assets 中.

and running rake assets:precompile should put those compiled assets into public/assets for you.

这篇关于Rails - 命名空间 Css 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆