How to configure Rails 3.2+/4 to generate .js instead of .js.coffee by default?(如何配置 Rails 3.2+/4 默认生成 .js 而不是 .js.coffee?)
问题描述
我已经看到这个问题的许多变体,其中所有答案都只是建议从 Gemfile
中删除 coffee-rails
gem(这个和这个).
I have seen a number of variations of this question where all the answers simply suggest removing the coffee-rails
gem from the Gemfile
(this one and this one).
这不是我要寻找的答案.我可能仍然想在项目中编写一些 CoffeeScript,我只是希望 JavaScript (.js
) 成为 Rails 生成器的默认值.
This is not the answer that I am looking for. I may still want to write some CoffeeScript in the project, I just want JavaScript (.js
) to be the default for the Rails generators.
这也意味着 将 .js.coffee
重命名为 .js
每次我生成代码的建议不是一个理想的解决方案.
This also means the suggestions to rename .js.coffee
to .js
every time I generate code is not a desirable solution.
我可以更改 Rails 中的某种配置以使 .js
成为默认配置,但仍然启用 CoffeeScript(资产管道应该仍然能够转译 .js.coffee
我可以写的文件)?
Is there some sort of configuration in Rails I can change to make .js
the default, but still leave CoffeeScript enabled (Asset Pipeline should still be able to transpile an .js.coffee
files that I may write)?
推荐答案
你可以通过 自定义生成器配置.
config.generators do |g|
g.javascript_engine :js
end
# or
config.generators.javascript_engine = :js
您可以在这里查看更多可用的配置选项.
这篇关于如何配置 Rails 3.2+/4 默认生成 .js 而不是 .js.coffee?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何配置 Rails 3.2+/4 默认生成 .js 而不是 .js.coffee?


- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01