This repository has been archived by the owner on Oct 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added form_errors partial and usage text
- Loading branch information
Showing
5 changed files
with
28 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
lib/generators/simple_form_haml/scaffold/templates/_form.haml.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
8 changes: 4 additions & 4 deletions
8
lib/generators/simple_form_haml/scaffold/templates/_form_errors.haml.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 1 addition & 1 deletion
2
lib/generators/simple_form_haml/scaffold/templates/show.haml.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters