ruby-on-rails - 默认情况下是哈姆尔

标签 ruby-on-rails haml ruby-on-rails-3.2

有没有办法配置rails默认使用haml,即当生成脚手架时,会生成相应的scaffold_name/index.html.haml而不是scaffold_name/index.html .erb

类似于将 config.sass.preferred_syntax = :sass 添加到 config/application.rb 并拥有 scaffold_name.sass 默认生成。

尝试将以下内容添加到config/application.rb

config.generators do |g| 
  g.template_engine :haml
end

但最终得到以下内容

$ rails generate scaffold foo name:string
  invoke  active_record
  create    db/migrate/20120208152550_create_foos.rb
  create    app/models/foo.rb
  invoke    test_unit
  create      test/unit/foo_test.rb
  create      test/fixtures/foos.yml
   route  resources :foos
  invoke  scaffold_controller
  create    app/controllers/foos_controller.rb
   error    haml [not found]
  invoke    test_unit
  create      test/functional/foos_controller_test.rb
  invoke    helper
  create      app/helpers/foos_helper.rb
  invoke      test_unit
  create        test/unit/helpers/foos_helper_test.rb
  invoke  assets
  invoke    coffee
  create      app/assets/javascripts/foos.js.coffee
  invoke    sass
  create      app/assets/stylesheets/foos.css.sass
  invoke  sass
  identical    app/assets/stylesheets/scaffolds.css.sass
$ rails destroy scaffold foo                                                                                                                        
  invoke  active_record
  remove    db/migrate/20120208152550_create_foos.rb
  remove    app/models/foo.rb
  invoke    test_unit
  remove      test/unit/foo_test.rb
  remove      test/fixtures/foos.yml
   route  resources :foos
  invoke  scaffold_controller
  remove    app/controllers/foos_controller.rb
   error    haml [not found]
  invoke    test_unit
  remove      test/functional/foos_controller_test.rb
  invoke    helper
  remove      app/helpers/foos_helper.rb
  invoke      test_unit
  remove        test/unit/helpers/foos_helper_test.rb
  invoke  assets
  invoke    coffee
  remove      app/assets/javascripts/foos.js.coffee
  invoke    sass
  remove      app/assets/stylesheets/foos.css.sass
  invoke  sass

我创建了一个漂亮的小捆绑命令,用 this 之后的 haml 文件替换所有 erb截屏视频,但我仍然有兴趣在创建脚手架时将其设置为默认值!如何使其默认生成 haml 文件(不是 erb!)?

最佳答案

我在 gemfile 中使用gem 'haml-rails', '= 0.3.4'。它会自动生成 *.html.haml ,无需任何配置。

关于ruby-on-rails - 默认情况下是哈姆尔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9187209/

相关文章:

ruby - 有条件地设置 CSS 类

ruby-on-rails - 如何获取 current_page?匹配多个 Action ?

ruby-on-rails - 多种产品类型的购物车的Rails方式

ruby-on-rails - 我收到错误 'Unknown key for a VALUE_STRING in [q]'

haml - html和sass值得学吗?

ruby-on-rails - 将 XML 文档导入 Rails 数据库?

ruby-on-rails - 我如何在我的 Gemfile 中找出依赖于 termios 的 gem?

json - 在rails中使用CoffeScript检索json数据

ruby-on-rails - 在 Ubuntu 12.04 上安装 gem pg 版本 0.12.2 时出错

ruby-on-rails - "temps.each(&:valid?)"在 Ruby 中是什么意思?