form_errors 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/form_errors.gemspec +23 -0
- data/lib/form_errors/railtie.rb +11 -0
- data/lib/form_errors/version.rb +3 -0
- data/lib/form_errors/view_helpers.rb +30 -0
- data/lib/form_errors.rb +10 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e7755c59d4cfab35a062714900bcebac57e2d575
|
4
|
+
data.tar.gz: d44605615a5c91e7f6eaef36f46e84840c72139c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a4f7db81e1d3b5460130073c58743b4b326d0b58b33012012ee941bac64d3b04d3f200eb6291a4010f2e782fd247de02e1a0b52e8555c1fc2374a92f0c604a15
|
7
|
+
data.tar.gz: f765ac6c33a50c81a7c96243e5beb8c282adb36f561bb573c973ca4fe7edfc40f757b8994c5fd54c7a3af2ac8ea1b703b728003f3f43f1596c3e58e564ebbde1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# FormErrors
|
2
|
+
|
3
|
+
Clean up form error reporting in Rails with a nice little view helper.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'form_errors'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install form_errors
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To display errors in your Rails form, you can call the `display_errors` view helper and pass along the object.
|
22
|
+
|
23
|
+
```html+erb
|
24
|
+
<%= simple_form_for(@product, html: { class: "form-horizontal" }) do |f| %>
|
25
|
+
<%= display_errors(@product) %>
|
26
|
+
<!-- ... -->
|
27
|
+
<% end %>
|
28
|
+
```
|
29
|
+
|
30
|
+
If you'd like to customize the error string within the `h2` tag, you can add a second parameter.
|
31
|
+
|
32
|
+
```html+erb
|
33
|
+
<%= simple_form_for(@product, html: { class: "form-horizontal" }) do |f| %>
|
34
|
+
<%= display_errors(@product, "We were unable to save that product.") %>
|
35
|
+
<!-- ... -->
|
36
|
+
<% end %>
|
37
|
+
```
|
38
|
+
|
39
|
+
The helper applies the `alert`, `alert-danger`, and `alert-dismissable` classes to the wrapper element. It also includes a `data-dismiss`. If you're using bootstrap, it ties in perfectly.
|
40
|
+
|
41
|
+
```html
|
42
|
+
<div class="alert alert-danger alert-dismissable">
|
43
|
+
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
44
|
+
<h2>
|
45
|
+
We were unable to save that product.
|
46
|
+
</h2>
|
47
|
+
<ul>
|
48
|
+
<li>Name can't be blank</li>
|
49
|
+
<li>Product definition can't be blank</li>
|
50
|
+
</ul>
|
51
|
+
</div>
|
52
|
+
```
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it ( http://github.com/johnotander/form_errors/fork )
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/form_errors.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'form_errors/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "form_errors"
|
8
|
+
spec.version = FormErrors::VERSION
|
9
|
+
spec.authors = ["John Otander"]
|
10
|
+
spec.email = ["johnotander@gmail.com"]
|
11
|
+
spec.summary = %q{Clean up form error reporting in Rails with a nice little view helper.}
|
12
|
+
spec.description = %q{Clean up form error reporting in Rails with a nice little view helper. <%= display_errors(@object) %>}
|
13
|
+
spec.homepage = "https://github.com/johnotander/form_errors"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module FormErrors
|
2
|
+
module ViewHelpers
|
3
|
+
def display_errors(object, error_string = nil)
|
4
|
+
return unless object && object.errors.any?
|
5
|
+
|
6
|
+
<<-HTML
|
7
|
+
<div class="alert alert-danger alert-dismissable">
|
8
|
+
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
9
|
+
<h2>
|
10
|
+
#{ get_error_string(error_string, object) }
|
11
|
+
</h2>
|
12
|
+
<ul>
|
13
|
+
#{ object.errors.full_messages.map do |msg|
|
14
|
+
"<li>#{ msg }</li>"
|
15
|
+
end.join }
|
16
|
+
</ul>
|
17
|
+
</div>
|
18
|
+
HTML
|
19
|
+
.html_safe
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_error_string(error_string, object)
|
25
|
+
error_string || "#{ pluralize(object.errors.count, "error") } "\
|
26
|
+
"prohibited this #{ object.class.name.underscore.humanize.downcase }"\
|
27
|
+
" from being saved"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/form_errors.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: form_errors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Otander
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Clean up form error reporting in Rails with a nice little view helper.
|
42
|
+
<%= display_errors(@object) %>
|
43
|
+
email:
|
44
|
+
- johnotander@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- form_errors.gemspec
|
55
|
+
- lib/form_errors.rb
|
56
|
+
- lib/form_errors/railtie.rb
|
57
|
+
- lib/form_errors/version.rb
|
58
|
+
- lib/form_errors/view_helpers.rb
|
59
|
+
homepage: https://github.com/johnotander/form_errors
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Clean up form error reporting in Rails with a nice little view helper.
|
83
|
+
test_files: []
|