Skip to content

Commit

Permalink
Change scaffold to use _form as partial and div's instead of paragrap…
Browse files Browse the repository at this point in the history
…hs. [#1760 status:resolved]
  • Loading branch information
josevalim committed Aug 30, 2009
1 parent 0fc5c59 commit 5d645c2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 31 deletions.
1 change: 0 additions & 1 deletion railties/lib/generators.rb
Expand Up @@ -45,7 +45,6 @@ module Generators
}, },


:erb => { :erb => {
:form => false,
:layout => true :layout => true
}, },


Expand Down
2 changes: 0 additions & 2 deletions railties/lib/generators/erb/scaffold/scaffold_generator.rb
Expand Up @@ -7,7 +7,6 @@ class ScaffoldGenerator < Base


argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"


class_option :form, :type => :boolean
class_option :layout, :type => :boolean class_option :layout, :type => :boolean
class_option :singleton, :type => :boolean, :desc => "Supply to skip index view" class_option :singleton, :type => :boolean, :desc => "Supply to skip index view"


Expand All @@ -33,7 +32,6 @@ def copy_new_file
end end


def copy_form_file def copy_form_file
return unless options[:form]
copy_view :_form copy_view :_form
end end


Expand Down
17 changes: 17 additions & 0 deletions 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 %>
16 changes: 2 additions & 14 deletions railties/lib/generators/erb/scaffold/templates/edit.html.erb
@@ -1,18 +1,6 @@
<h1>Editing <%= singular_name %></h1> <h1>Editing <%= singular_name %></h1>


<%% form_for(@<%= singular_name %>) do |f| %> <%%= render 'form' %>
<%%= 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 %>


<%%= link_to 'Show', @<%= singular_name %> %> | <%%= link_to 'Show', @<%= singular_name %> %> |
<%%= link_to 'Back', <%= plural_name %>_path %> <%%= link_to 'Back', <%= plural_name %>_path %>
16 changes: 2 additions & 14 deletions railties/lib/generators/erb/scaffold/templates/new.html.erb
@@ -1,17 +1,5 @@
<h1>New <%= singular_name %></h1> <h1>New <%= singular_name %></h1>


<%% form_for(@<%= singular_name %>) do |f| %> <%%= render 'form' %>
<%%= f.error_messages %>


<% for attribute in attributes -%> <%%= link_to 'Back', <%= plural_name %>_path %>
<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 %>
Expand Up @@ -16,6 +16,10 @@ a { color: #000; }
a:visited { color: #666; } a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; } a:hover { color: #fff; background-color:#000; }


div.attribute, div.action {
margin-bottom: 10px;
}

.fieldWithErrors { .fieldWithErrors {
padding: 2px; padding: 2px;
background-color: red; background-color: red;
Expand Down

7 comments on commit 5d645c2

@jerome
Copy link

@jerome jerome commented on 5d645c2 Aug 30, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@masterkain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because form is the partial's name?

@saturnflyer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

@josh josh commented on 5d645c2 Aug 30, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@saturnflyer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@clemens
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mislav
Copy link
Member

@mislav mislav commented on 5d645c2 Aug 31, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w00t!

Please sign in to comment.