From 5d645c271b350c2a3ed7fd835e539322cda61d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 30 Aug 2009 16:53:23 +0200 Subject: Change scaffold to use _form as partial and div's instead of paragraphs. [#1760 status:resolved] --- railties/lib/generators.rb | 1 - .../lib/generators/erb/scaffold/scaffold_generator.rb | 2 -- .../generators/erb/scaffold/templates/_form.html.erb | 17 +++++++++++++++++ .../lib/generators/erb/scaffold/templates/edit.html.erb | 16 ++-------------- .../lib/generators/erb/scaffold/templates/new.html.erb | 16 ++-------------- .../generators/rails/stylesheets/templates/scaffold.css | 4 ++++ 6 files changed, 25 insertions(+), 31 deletions(-) create mode 100644 railties/lib/generators/erb/scaffold/templates/_form.html.erb diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb index 5c03787aee..879abb1c41 100644 --- a/railties/lib/generators.rb +++ b/railties/lib/generators.rb @@ -45,7 +45,6 @@ module Rails }, :erb => { - :form => false, :layout => true }, diff --git a/railties/lib/generators/erb/scaffold/scaffold_generator.rb b/railties/lib/generators/erb/scaffold/scaffold_generator.rb index 955f22192a..f146a1b1da 100644 --- a/railties/lib/generators/erb/scaffold/scaffold_generator.rb +++ b/railties/lib/generators/erb/scaffold/scaffold_generator.rb @@ -7,7 +7,6 @@ module Erb argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" - class_option :form, :type => :boolean class_option :layout, :type => :boolean class_option :singleton, :type => :boolean, :desc => "Supply to skip index view" @@ -33,7 +32,6 @@ module Erb end def copy_form_file - return unless options[:form] copy_view :_form end diff --git a/railties/lib/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/generators/erb/scaffold/templates/_form.html.erb new file mode 100644 index 0000000000..473ebe14fb --- /dev/null +++ b/railties/lib/generators/erb/scaffold/templates/_form.html.erb @@ -0,0 +1,17 @@ +<%% form_for(@<%= singular_name %>) do |f| %> + <%%= f.error_messages %> + +<% for attribute in attributes -%> +
+ <%%= f.label :<%= attribute.name %> %>
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> +
+<% end -%> +
+ <%% if @<%= singular_name %>.new_record? %> + <%%= f.submit 'Create' %> + <%% else %> + <%%= f.submit 'Update' %> + <%% end %> +
+<%% end %> diff --git a/railties/lib/generators/erb/scaffold/templates/edit.html.erb b/railties/lib/generators/erb/scaffold/templates/edit.html.erb index cca1d61c68..5bc507ffc8 100644 --- a/railties/lib/generators/erb/scaffold/templates/edit.html.erb +++ b/railties/lib/generators/erb/scaffold/templates/edit.html.erb @@ -1,18 +1,6 @@

Editing <%= singular_name %>

-<%% form_for(@<%= singular_name %>) do |f| %> - <%%= f.error_messages %> - -<% for attribute in attributes -%> -

- <%%= f.label :<%= attribute.name %> %>
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> -

-<% end -%> -

- <%%= f.submit 'Update' %> -

-<%% end %> +<%%= render 'form' %> <%%= link_to 'Show', @<%= singular_name %> %> | -<%%= link_to 'Back', <%= plural_name %>_path %> \ No newline at end of file +<%%= link_to 'Back', <%= plural_name %>_path %> diff --git a/railties/lib/generators/erb/scaffold/templates/new.html.erb b/railties/lib/generators/erb/scaffold/templates/new.html.erb index 96c89fc50e..9a1c489331 100644 --- a/railties/lib/generators/erb/scaffold/templates/new.html.erb +++ b/railties/lib/generators/erb/scaffold/templates/new.html.erb @@ -1,17 +1,5 @@

New <%= singular_name %>

-<%% form_for(@<%= singular_name %>) do |f| %> - <%%= f.error_messages %> +<%%= render 'form' %> -<% for attribute in attributes -%> -

- <%%= f.label :<%= attribute.name %> %>
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> -

-<% end -%> -

- <%%= f.submit 'Create' %> -

-<%% end %> - -<%%= link_to 'Back', <%= plural_name %>_path %> \ No newline at end of file +<%%= link_to 'Back', <%= plural_name %>_path %> diff --git a/railties/lib/generators/rails/stylesheets/templates/scaffold.css b/railties/lib/generators/rails/stylesheets/templates/scaffold.css index 093c20994d..163f11441c 100644 --- a/railties/lib/generators/rails/stylesheets/templates/scaffold.css +++ b/railties/lib/generators/rails/stylesheets/templates/scaffold.css @@ -16,6 +16,10 @@ a { color: #000; } a:visited { color: #666; } a:hover { color: #fff; background-color:#000; } +div.attribute, div.action { + margin-bottom: 10px; +} + .fieldWithErrors { padding: 2px; background-color: red; -- cgit v1.2.3