可以在Rails中使用stylesheet.css.erb? [英] Possible to use stylesheet.css.erb in Rails?

查看:166
本文介绍了可以在Rails中使用stylesheet.css.erb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我是Rails和Ruby的新手。我想知道是否可以使用嵌入式ruby css文件(css.erb),类似于使用html.erb文件的视图。

Hey, I'm new to Rails and Ruby in general. I was wondering if it's possible to use an embedded ruby css file (css.erb), similar to using html.erb files for views.

例如,我使用

<%= stylesheet_link_tag "main" %>

链接到public / stylesheets中的main.css文件,但是当我更改文件扩展名main.css到main.css.erb,它不再渲染css ..

to link to my main.css file in public/stylesheets, but when I change the file extension from main.css to main.css.erb, it no longer renders the css..

这是可能的,还是有更好的方法?

Is this even possible, or is there a better way?

推荐答案

我不这么认为。你的意图是什么 - 使用变量,并在运行时或编译时间(意味着部署时间?)进行评估。此外,什么是ERB绑定?它会绑定到控制器,如视图和助手,以便ERB实例将有权访问在控制器中设置的实例变量?我只是把这个问题作为一个理论练习。

I dont think so. Whats your intention - to use variables and have them be evaluated at runtime, or "compile" time (meaning like deploy time?). Also, what would be the ERB binding? Would it bind to the controller, like views and helpers are, so that ERB instance would have access to the instance variables set in the controller? I just pose this question as more of a theoretical exercise.

如果你想在CSS中使用变量,你可以使用Haml的SASS。你不能访问控制器的范围,但你得到基本的变量和循环。还有其他很酷的东西,比如mixins。

If you want to use variables in your CSS than you can use Haml's SASS. You dont get access to the controller's scope but you do get basic variables and looping. Plus other cool stuff like mixins.

这篇关于可以在Rails中使用stylesheet.css.erb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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