Permalink
Browse files

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

…hs. [#1760 status:resolved]
  • Loading branch information...
josevalim committed Aug 30, 2009
1 parent 0fc5c59 commit 5d645c271b350c2a3ed7fd835e539322cda61d8c
@@ -45,7 +45,6 @@ module Generators
},
:erb => {
- :form => false,
:layout => true
},
@@ -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
@@ -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 %>
@@ -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 %>
@@ -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 %>
@@ -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

This comment has been minimized.

Show comment
Hide comment
@jerome

jerome Aug 30, 2009

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

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

@masterkain

This comment has been minimized.

Show comment
Hide comment
@masterkain

masterkain Aug 30, 2009

Contributor

because form is the partial's name?

Contributor

masterkain replied Aug 30, 2009

because form is the partial's name?

@saturnflyer

This comment has been minimized.

Show comment
Hide comment
@saturnflyer

saturnflyer Aug 30, 2009

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

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

This comment has been minimized.

Show comment
Hide comment
@josh

josh Aug 30, 2009

Member

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

Member

josh replied 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

This comment has been minimized.

Show comment
Hide comment
@saturnflyer

saturnflyer Aug 30, 2009

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

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

@clemens

This comment has been minimized.

Show comment
Hide comment
@clemens

clemens Aug 30, 2009

Contributor

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

Contributor

clemens replied Aug 30, 2009

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

@mislav

This comment has been minimized.

Show comment
Hide comment
@mislav

mislav Aug 31, 2009

Member

w00t!

Member

mislav replied Aug 31, 2009

w00t!

Please sign in to comment.