diff --git a/lib/generators/simple_form/install_generator.rb b/lib/generators/simple_form/install_generator.rb index be1e1830e..8c001ba81 100644 --- a/lib/generators/simple_form/install_generator.rb +++ b/lib/generators/simple_form/install_generator.rb @@ -13,7 +13,11 @@ def copy_locale_file end def copy_scaffold_template - copy_file '_form.html.erb', 'lib/templates/erb/scaffold/_form.html.erb' + if Rails::Generators.options[:rails][:template_engine] == :haml + copy_file '_form.html.haml', 'lib/templates/haml/scaffold/_form.html.haml' + else + copy_file '_form.html.erb', 'lib/templates/erb/scaffold/_form.html.erb' + end end end end diff --git a/lib/generators/simple_form/templates/_form.html.haml b/lib/generators/simple_form/templates/_form.html.haml new file mode 100644 index 000000000..601a3d266 --- /dev/null +++ b/lib/generators/simple_form/templates/_form.html.haml @@ -0,0 +1,18 @@ += simple_form_for(@<%= singular_name %>) do |f| + - if @<%= singular_name %>.errors.any? + #error_explanation + %h2 + = pluralize(@<%= singular_name %>.errors.count, "error") + prohibited this <%= singular_name %> from being saved: + + %ul + - @<%= singular_name %>.errors.full_messages.each do |msg| + %li= msg + + .inputs + <%- attributes.each do |attribute| -%> + = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> + <%- end -%> + + .actions + = f.button :submit