有没有一种方法可以将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

我创建了一个不错的bundle命令,在this截屏后将所有erb替换为haml文件,但我仍然对在创建支架时将其设置为默认值感兴趣!如何使默认情况下生成haml文件(不是erb!)?

最佳答案

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

关于ruby-on-rails - 默认为haml,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9187209/

10-13 04:49