问题描述
我正在处理一个 Ruby on Rails 项目,我需要自定义由 Gems 提供的默认视图.
I am working on a Ruby on Rails project and am needing to customize default views provided by Gems.
要求是模板使用Slim.我知道 ERB 是 Rails 的默认模板引擎.
The requirement is to use Slim for template. I understand that ERB is the default template engine for Rails.
根据我的观察,优先级是 ERB,否则将使用 Slim/Haml 视图.
As per my observation, the priority is for ERB and if not it will use Slim/Haml views.
我想知道是否可以将 Slim 设置为默认值而不是 ERB?
I am interested in knowing if it is possible to set Slim as the default instead of the ERB?
如何做到这一点,以便当我在 Slim 中创建模板的本地版本时,它将覆盖 gem 提供的模板.
How can this be achieved so that when I create a local version of a template in Slim it will override the template provided by the gem.
任何线索将不胜感激.
推荐答案
您可以使用slim-rails" gem,默认情况下它是为生成 slim 模板而构建的.
You can use "slim-rails" gem which is built for generating slim template as default.
https://github.com/slim-template/slim-rails
只需在您的 Gemfile 中将 gem 'slim'
替换为 gem 'slim-rails'
即可.
Just replace gem 'slim'
by gem 'slim-rails'
in your Gemfile.
这篇关于Ruby on Rails - 使 Slim 成为默认模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!