Skip to content
Browse files

Change scaffold to use _form as partial and div's instead of paragrap…

…hs. [#1760 status:resolved]
  • Loading branch information...
1 parent 0fc5c59 commit 5d645c271b350c2a3ed7fd835e539322cda61d8c @josevalim josevalim committed Aug 30, 2009
View
1 railties/lib/generators.rb
@@ -45,7 +45,6 @@ module Generators
},
:erb => {
- :form => false,
:layout => true
},
View
2 railties/lib/generators/erb/scaffold/scaffold_generator.rb
@@ -7,7 +7,6 @@ class ScaffoldGenerator < Base
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 @@ def copy_new_file
end
def copy_form_file
- return unless options[:form]
copy_view :_form
end
View
17 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 -%>
+ <div class="attribute">
+ <%%= f.label :<%= attribute.name %> %><br />
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
+ </div>
+<% end -%>
+ <div class="action">
+ <%% if @<%= singular_name %>.new_record? %>
+ <%%= f.submit 'Create' %>
+ <%% else %>
+ <%%= f.submit 'Update' %>
+ <%% end %>
+ </div>
+<%% end %>
View
16 railties/lib/generators/erb/scaffold/templates/edit.html.erb
@@ -1,18 +1,6 @@
<h1>Editing <%= singular_name %></h1>
-<%% form_for(@<%= singular_name %>) do |f| %>
- <%%= f.error_messages %>
-
-<% for attribute in attributes -%>
- <p>
- <%%= f.label :<%= attribute.name %> %><br />
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
- </p>
-<% end -%>
- <p>
- <%%= f.submit 'Update' %>
- </p>
-<%% end %>
+<%%= render 'form' %>
<%%= link_to 'Show', @<%= singular_name %> %> |
-<%%= link_to 'Back', <%= plural_name %>_path %>
+<%%= link_to 'Back', <%= plural_name %>_path %>
View
16 railties/lib/generators/erb/scaffold/templates/new.html.erb
@@ -1,17 +1,5 @@
<h1>New <%= singular_name %></h1>
-<%% form_for(@<%= singular_name %>) do |f| %>
- <%%= f.error_messages %>
+<%%= render 'form' %>
-<% for attribute in attributes -%>
- <p>
- <%%= f.label :<%= attribute.name %> %><br />
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
- </p>
-<% end -%>
- <p>
- <%%= f.submit 'Create' %>
- </p>
-<%% end %>
-
-<%%= link_to 'Back', <%= plural_name %>_path %>
+<%%= link_to 'Back', <%= plural_name %>_path %>
View
4 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;

7 comments on commit 5d645c2

@jerome
jerome commented on 5d645c2 Aug 30, 2009

why not "render f" instead of render 'form' ??

@masterkain

because form is the partial's name?

@saturnflyer

jerome, unless I'm missing something, it's because there is no 'f' object to render. "render 'form'" will render the "_form.html.erb"

@josh
Ruby on Rails member
josh commented on 5d645c2 Aug 30, 2009

I actually use "render f" more often. Keep form_for in the template and only put the fields in the _form partial.

@saturnflyer

i agree then. keeping the form_for and doing render f.

@clemens

Oh, how I love the divs ... Thanks José! :-)

@mislav
Ruby on Rails member
mislav commented on 5d645c2 Aug 31, 2009

w00t!

Please sign in to comment.
Something went wrong with that request. Please try again.