如何关闭 Rails 3.1 上的自动样式表/javascript 生成?

发布于 2024-12-03 13:53:38 字数 687 浏览 2 评论 0 原文

我正在开发一个 Rails 3.1 项目,但我不希望分别生成 controller_name.css.sasscontroller_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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

顾北清歌寒 2024-12-10 13:53:38

将这些行添加到 application.rb 中:

config.generators.stylesheets = false
config.generators.javascripts = false

Add these lines to application.rb:

config.generators.stylesheets = false
config.generators.javascripts = false
海之角 2024-12-10 13:53:38

新语法是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 of generate. And you can skip the creation of a controller helper using the --no-helper flag.

泡沫很甜 2024-12-10 13:53:38

仅使用一次:

rails generate controller controller_name --no-assets

For just one time, use:

rails generate controller controller_name --no-assets
谎言月老 2024-12-10 13:53:38

@Dmitry Maksimov 对 Rails 4.2 的回答的更新。默认情况下,您可以使用 config/application.rb 文件中的以下内容禁用特定于控制器的资产文件的生成(来源:指南):

config.generators do |g|
  g.assets false
end

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):

config.generators do |g|
  g.assets false
end
尝蛊 2024-12-10 13:53:38

我在 application.rb 文件中的全部选项:

config.generators do |g|
    g.stylesheets = false
    g.javascripts = false
    g.test_framework  :rspec, fixture: false
    g.template_engine :haml
    g.fixture_replacement :factory_girl, dir: 'spec/factories'
end

My whole options in the application.rb file:

config.generators do |g|
    g.stylesheets = false
    g.javascripts = false
    g.test_framework  :rspec, fixture: false
    g.template_engine :haml
    g.fixture_replacement :factory_girl, dir: 'spec/factories'
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文