Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
Added form_errors partial and usage text
Browse files Browse the repository at this point in the history
  • Loading branch information
sporkd committed May 13, 2010
1 parent f30b6cb commit 2b4a166
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
20 changes: 16 additions & 4 deletions lib/generators/simple_form_haml/USAGE
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
Description:
Explain the generator
This generator creates haml views for use with the simple_form gem
by Plataforma Tec. It also uses the show_for gem for displaying
model attributes in the show.html.haml that it generates.

Before you can use this generator you need to install both gems:

gem install simple_form
gem install show_for

Example:
rails generate simple_form_haml Thing

rails generate simple_form_haml:scaffold Thing
This will create:
what/will/it/create
app/views/things/index.html.haml
app/views/things/edit.html.haml
app/views/things/show.html.haml
app/views/things/new.html.haml
app/views/things/_form.html.haml
app/views/shared/_form_errors.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ def copy_layout_file
File.join("app/views/layouts", controller_class_path, "#{controller_file_name}.html.haml")
end

def copy_shared_files
template "_form_errors.haml.erb",
File.join("app/views/shared", "_form_errors.html.haml")
end

def copy_view_files
views = available_views
views.delete("index") if options[:singleton]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
- simple_form_for @<%= singular_name %> do |form|
= render 'form_errors'
= render :partial => 'shared/form_errors', :locals => { :resource => @<%= singular_name %> }

<%- for attribute in attributes -%>
= form.input :<%= attribute.name %>, :label => '<%= attribute.name.titleize %>'
<%- end -%>

.actions
= form.button :submit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-if @<%= singular_name %>.errors.any?
-if resource.errors.any?
#errorExplanation
%h2= "#{pluralize(@<%= singular_name %>.errors.count, "error")} prohibited this <%= singular_name %> from being saved:"
%h2= "#{pluralize(resource.errors.count, "error")} prohibited this #{resource.class.name.titleize} from being saved:"
%ul
- @<%= singular_name %>.errors.full_messages.each do |msg|
%li= msg
- resource.errors.full_messages.each do |msg|
%li= msg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%h1 <%= singular_name %>

- show_for @<%= singular_name %> do |a| %>
- show_for @<%= singular_name %> do |a|
<%- for attribute in attributes -%>
= a.attribute :<%= attribute.name %>
<%- end -%>
Expand Down

0 comments on commit 2b4a166

Please sign in to comment.