通过调用sass编译器,这在理论上是可能的。请注意,您希望使用css而不是scss请求。客户端没有理由需要知道文件是如何生成的。
<%= stylesheet_link_tag(about_me_user_path(current_user, format: :css), media: 'all', class: "home_about_me_css") %>
class UsersController
def user_profile_stylesheet
respond_to do |f|
f.css do
fn = Rails.root.join('app', 'views', 'home', 'home_stylesheet.css.scss.erb')
sass = render_to_string(file: fn)
css = SassC::Engine.new(sass, style: :compressed).render
render text: css
end
end
end
end
我不太确定这是你真正想在生产环境中做的事情,因为它要求你在响应请求时在运行时编译sass。而且,您将无法在资产管道中引用任何类似SASS函数的内容,因为这是在管道外编译的。
这也是一场安全噩梦,因为SASS不像CSS那样只是声明性的。这可能会被用来在您的服务器上执行代码。
无论你想做什么,都必须有一个更聪明/更简单的解决方案。