我正在开发一个 Rails 3.1 项目,但我不希望分别生成 controller_name.css.sass
和 controller_name.js.coffee
当我运行railsgeneratecontrollercontroller_name
时。我可以发誓我在互联网上的某个地方看到过这个设置,但我现在怎么也找不到它。它是什么?
请记住,我仍然想使用 Asset Pipeline 和 CoffeeScript/Sass 集成,但我正在以自己的方式组织这些文件。
我很确定答案是命令行参数,但是通过生成器设置或隐藏文件或其他东西将其关闭有加分。
编辑:我找到了它的命令行标志。
rails generate controller controller_name --assets=false
或者类似的东西(该行实际上出错了,但它也不会生成资产)。 API 此处 显示 :assets =>; true
作为默认选项。如何将其更改为 false 并使其在每次生成控制器时始终为 false?
I've got a Rails 3.1 project that I'm working on, but I don't want controller_name.css.sass
and controller_name.js.coffee
to be generated each time I run rails generate controller controller_name
. I could swear I've seen the setting somewhere on the internet, but I can't find it now for the life of me. What is it?
Keep in mind that I'm still wanting to use the Asset Pipeline and the CoffeeScript/Sass integration, but I'm organizing those files in my own way.
I'm pretty sure the answer is a command line argument, but bonus points for turning it off with a generator setting or a hidden file or something.
EDIT: I've found the command line flag for it.
rails generate controller controller_name --assets=false
Or something of the like (that line actually errors out, but it also doesn't generate the assets). The API here shows :assets => true
as a default option. How do I change that to false and have it always be false every time I generate a controller?
发布评论
评论(5)
将这些行添加到
application.rb
中:Add these lines to
application.rb
:新语法是
railsgeneratecontrollerResources--no-assets
。不要忘记您还可以使用
g
代替generate
。您可以使用--no-helper
标志跳过控制器助手的创建。New syntax is
rails generate controller Resources --no-assets
.Don't forget you can also use
g
in place ofgenerate
. And you can skip the creation of a controller helper using the--no-helper
flag.仅使用一次:
For just one time, use:
@Dmitry Maksimov 对 Rails 4.2 的回答的更新。默认情况下,您可以使用
config/application.rb
文件中的以下内容禁用特定于控制器的资产文件的生成(来源:指南):An update on @Dmitry Maksimov's answer for Rails 4.2. You can disable generation of controller-specific asset files by default with the following in your
config/application.rb
file (source: the guide):我在 application.rb 文件中的全部选项:
My whole options in the application.rb file: