dynamic_form 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/README.md +57 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/dynamic_form.gemspec +6 -5
- data/lib/active_model/dynamic_errors.rb +47 -0
- data/lib/active_model/locale/en.yml +4 -0
- data/lib/dynamic_form.rb +1 -0
- data/test/dynamic_form_test.rb +6 -0
- metadata +8 -7
- data/README +0 -13
- data/dynamic-form.gemspec +0 -58
data/.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
.bundle
|
1
|
+
.bundle
|
2
|
+
pkg
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
DynamicForm
|
2
|
+
===========
|
3
|
+
|
4
|
+
DynamicForm holds a few helpers method to help you deal with your Rails3 models, they are:
|
5
|
+
|
6
|
+
* `input(record, method, options = {})`
|
7
|
+
* `form(record, options = {})`
|
8
|
+
* `error_message_on(object, method, options={})`
|
9
|
+
* `error_messages_for(record, options={})`
|
10
|
+
|
11
|
+
It also adds `f.error_messages` and `f.error_messages_on` to your form builders.
|
12
|
+
|
13
|
+
Read `/lib/action_view/helpers/dynamic_form.rb` for details of each method.
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
DynamicErrors
|
18
|
+
=============
|
19
|
+
|
20
|
+
DynamicForm also includes DynamicErrors, which is a port of the custom-err-messages plugin,
|
21
|
+
but built to work with Rails3. It gives you the option to not have your custom validation
|
22
|
+
error message prefixed with the attribute name. Ordinarily, if you have, say:
|
23
|
+
|
24
|
+
validates_acceptance_of :accepted_terms, :message => 'Please accept the terms of service'
|
25
|
+
|
26
|
+
You'll get the following error message:
|
27
|
+
|
28
|
+
Accepted terms Please accept the terms of service
|
29
|
+
|
30
|
+
This plugin allows you to omit the attribute name for specific messages. All you have to do
|
31
|
+
is begin the message with a '^' character. Example:
|
32
|
+
|
33
|
+
validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
|
34
|
+
|
35
|
+
Nigel Ramsay added the ability to specify a proc to generate the message.
|
36
|
+
|
37
|
+
validates_presence_of :assessment_answer_option_id,
|
38
|
+
:message => Proc.new { |aa| "#{aa.label} (#{aa.group_label}) is required" }
|
39
|
+
|
40
|
+
which gives an error message like: Rate (Accuracy) is required
|
41
|
+
|
42
|
+
---
|
43
|
+
|
44
|
+
Installation
|
45
|
+
------------
|
46
|
+
|
47
|
+
DynamicForm can be installed as a gem in your `Gemfile`:
|
48
|
+
|
49
|
+
gem 'dynamic_form'
|
50
|
+
|
51
|
+
or as a plugin by running this command:
|
52
|
+
|
53
|
+
rails plugin install git://codaset.com/joelmoss/dynamic-form.git
|
54
|
+
|
55
|
+
---
|
56
|
+
|
57
|
+
Copyright (c) 2010 David Heinemeier Hansson, released under the MIT license
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "dynamic_form"
|
8
8
|
gem.summary = %Q{DynamicForm holds a few helper methods to help you deal with your Rails3 models}
|
9
|
-
gem.description = %Q{DynamicForm holds a few helper methods to help you deal with your Rails3 models. It includes the stripped out methods from Rails 2; error_message_on and error_messages_for}
|
9
|
+
gem.description = %Q{DynamicForm holds a few helper methods to help you deal with your Rails3 models. It includes the stripped out methods from Rails 2; error_message_on and error_messages_for. It also brings in the functionality of the custom-err-messages plugin, which provides more flexibility over your model error messages.}
|
10
10
|
gem.email = "joel@developwithstyle.com"
|
11
11
|
gem.homepage = "http://codaset.com/joelmoss/dynamic-form"
|
12
12
|
gem.authors = ["Joel Moss"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.1
|
data/dynamic_form.gemspec
CHANGED
@@ -5,29 +5,30 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dynamic_form}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joel Moss"]
|
12
12
|
s.date = %q{2010-08-09}
|
13
|
-
s.description = %q{DynamicForm holds a few helper methods to help you deal with your Rails3 models. It includes the stripped out methods from Rails 2; error_message_on and error_messages_for}
|
13
|
+
s.description = %q{DynamicForm holds a few helper methods to help you deal with your Rails3 models. It includes the stripped out methods from Rails 2; error_message_on and error_messages_for. It also brings in the functionality of the custom-err-messages plugin, which provides more flexibility over your model error messages.}
|
14
14
|
s.email = %q{joel@developwithstyle.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
|
-
"README"
|
16
|
+
"README.md"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".gitignore",
|
20
20
|
"Gemfile",
|
21
21
|
"Gemfile.lock",
|
22
22
|
"MIT-LICENSE",
|
23
|
-
"README",
|
23
|
+
"README.md",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
|
-
"dynamic-form.gemspec",
|
27
26
|
"dynamic_form.gemspec",
|
28
27
|
"init.rb",
|
29
28
|
"lib/action_view/helpers/dynamic_form.rb",
|
30
29
|
"lib/action_view/locale/en.yml",
|
30
|
+
"lib/active_model/dynamic_errors.rb",
|
31
|
+
"lib/active_model/locale/en.yml",
|
31
32
|
"lib/dynamic_form.rb",
|
32
33
|
"test/dynamic_form_i18n_test.rb",
|
33
34
|
"test/dynamic_form_test.rb",
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
class Errors
|
3
|
+
# Redefine the ActiveModel::Errors::full_messages method:
|
4
|
+
# Returns all the full error messages in an array. 'Base' messages are handled as usual.
|
5
|
+
# Non-base messages are prefixed with the attribute name as usual UNLESS
|
6
|
+
# (1) they begin with '^' in which case the attribute name is omitted.
|
7
|
+
# E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
|
8
|
+
# (2) the message is a proc, in which case the proc is invoked on the model object.
|
9
|
+
# E.g. validates_presence_of :assessment_answer_option_id,
|
10
|
+
# :message => Proc.new { |aa| "#{aa.label} (#{aa.group_label}) is required" }
|
11
|
+
# which gives an error message like:
|
12
|
+
# Rate (Accuracy) is required
|
13
|
+
def full_messages
|
14
|
+
full_messages = []
|
15
|
+
|
16
|
+
each do |attribute, messages|
|
17
|
+
messages = Array.wrap(messages)
|
18
|
+
next if messages.empty?
|
19
|
+
|
20
|
+
if attribute == :base
|
21
|
+
messages.each {|m| full_messages << m }
|
22
|
+
else
|
23
|
+
attr_name = attribute.to_s.gsub('.', '_').humanize
|
24
|
+
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
|
25
|
+
options = { :default => "%{attribute} %{message}", :attribute => attr_name }
|
26
|
+
|
27
|
+
messages.each do |m|
|
28
|
+
if m =~ /^\^/
|
29
|
+
options[:default] = "%{message}"
|
30
|
+
full_messages << I18n.t(:"errors.dynamic_format", options.merge(:message => m[1..-1]))
|
31
|
+
elsif m.is_a? Proc
|
32
|
+
options[:default] = "%{message}"
|
33
|
+
full_messages << I18n.t(:"errors.dynamic_format", options.merge(:message => m.call(@base)))
|
34
|
+
else
|
35
|
+
full_messages << I18n.t(:"errors.format", options.merge(:message => m))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
full_messages
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'active_support/i18n'
|
47
|
+
I18n.load_path << File.dirname(__FILE__) + '/locale/en.yml'
|
data/lib/dynamic_form.rb
CHANGED
data/test/dynamic_form_test.rb
CHANGED
@@ -369,4 +369,10 @@ class DynamicFormTest < ActionView::TestCase
|
|
369
369
|
|
370
370
|
assert_dom_equal expected, output_buffer
|
371
371
|
end
|
372
|
+
|
373
|
+
def test_error_messages_without_prefixed_attribute_name
|
374
|
+
error = error_messages_for(@post)
|
375
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>),
|
376
|
+
error
|
377
|
+
end
|
372
378
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 1.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joel Moss
|
@@ -30,27 +30,28 @@ dependencies:
|
|
30
30
|
version: "0"
|
31
31
|
type: :development
|
32
32
|
version_requirements: *id001
|
33
|
-
description: DynamicForm holds a few helper methods to help you deal with your Rails3 models. It includes the stripped out methods from Rails 2; error_message_on and error_messages_for
|
33
|
+
description: DynamicForm holds a few helper methods to help you deal with your Rails3 models. It includes the stripped out methods from Rails 2; error_message_on and error_messages_for. It also brings in the functionality of the custom-err-messages plugin, which provides more flexibility over your model error messages.
|
34
34
|
email: joel@developwithstyle.com
|
35
35
|
executables: []
|
36
36
|
|
37
37
|
extensions: []
|
38
38
|
|
39
39
|
extra_rdoc_files:
|
40
|
-
- README
|
40
|
+
- README.md
|
41
41
|
files:
|
42
42
|
- .gitignore
|
43
43
|
- Gemfile
|
44
44
|
- Gemfile.lock
|
45
45
|
- MIT-LICENSE
|
46
|
-
- README
|
46
|
+
- README.md
|
47
47
|
- Rakefile
|
48
48
|
- VERSION
|
49
|
-
- dynamic-form.gemspec
|
50
49
|
- dynamic_form.gemspec
|
51
50
|
- init.rb
|
52
51
|
- lib/action_view/helpers/dynamic_form.rb
|
53
52
|
- lib/action_view/locale/en.yml
|
53
|
+
- lib/active_model/dynamic_errors.rb
|
54
|
+
- lib/active_model/locale/en.yml
|
54
55
|
- lib/dynamic_form.rb
|
55
56
|
- test/dynamic_form_i18n_test.rb
|
56
57
|
- test/dynamic_form_test.rb
|
data/README
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
DynamicForm
|
2
|
-
===========
|
3
|
-
|
4
|
-
DynamicForm holds a few helpers method to help you deal with your models, they are:
|
5
|
-
|
6
|
-
* input(record, method, options = {})
|
7
|
-
* form(record, options = {})
|
8
|
-
* error_message_on(object, method, options={})
|
9
|
-
* error_messages_for(record, options={})
|
10
|
-
|
11
|
-
It also adds f.error_messages and f.error_messages_on to your form builders.
|
12
|
-
|
13
|
-
Copyright (c) 2010 David Heinemeier Hansson, released under the MIT license
|
data/dynamic-form.gemspec
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{dynamic-form}
|
8
|
-
s.version = "1.0.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Joel Moss"]
|
12
|
-
s.date = %q{2010-08-09}
|
13
|
-
s.description = %q{DynamicForm holds a few helper methods to help you deal with your Rails3 models. It includes the stripped out methods from Rails 2; error_message_on and error_messages_for}
|
14
|
-
s.email = %q{joel@developwithstyle.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".gitignore",
|
20
|
-
"Gemfile",
|
21
|
-
"Gemfile.lock",
|
22
|
-
"MIT-LICENSE",
|
23
|
-
"README",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"dynamic-form.gemspec",
|
27
|
-
"init.rb",
|
28
|
-
"lib/action_view/helpers/dynamic_form.rb",
|
29
|
-
"lib/action_view/locale/en.yml",
|
30
|
-
"test/dynamic_form_i18n_test.rb",
|
31
|
-
"test/dynamic_form_test.rb",
|
32
|
-
"test/test_helper.rb"
|
33
|
-
]
|
34
|
-
s.homepage = %q{http://codaset.com/joelmoss/dynamic-form}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
-
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.3.7}
|
38
|
-
s.summary = %q{DynamicForm holds a few helper methods to help you deal with your Rails3 models}
|
39
|
-
s.test_files = [
|
40
|
-
"test/dynamic_form_i18n_test.rb",
|
41
|
-
"test/dynamic_form_test.rb",
|
42
|
-
"test/test_helper.rb"
|
43
|
-
]
|
44
|
-
|
45
|
-
if s.respond_to? :specification_version then
|
46
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
-
s.specification_version = 3
|
48
|
-
|
49
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
-
s.add_development_dependency(%q<mocha>, [">= 0"])
|
51
|
-
else
|
52
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
53
|
-
end
|
54
|
-
else
|
55
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|