dynamic_form 1.0.0 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
- .bundle
1
+ .bundle
2
+ pkg
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'rails', '3.0.0.rc'
3
+ gem 'rails', '3.0.0'
4
4
  gem 'mocha'
data/Gemfile.lock CHANGED
@@ -2,34 +2,34 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  abstract (1.0.0)
5
- actionmailer (3.0.0.rc)
6
- actionpack (= 3.0.0.rc)
5
+ actionmailer (3.0.0)
6
+ actionpack (= 3.0.0)
7
7
  mail (~> 2.2.5)
8
- actionpack (3.0.0.rc)
9
- activemodel (= 3.0.0.rc)
10
- activesupport (= 3.0.0.rc)
8
+ actionpack (3.0.0)
9
+ activemodel (= 3.0.0)
10
+ activesupport (= 3.0.0)
11
11
  builder (~> 2.1.2)
12
12
  erubis (~> 2.6.6)
13
13
  i18n (~> 0.4.1)
14
14
  rack (~> 1.2.1)
15
- rack-mount (~> 0.6.9)
15
+ rack-mount (~> 0.6.12)
16
16
  rack-test (~> 0.5.4)
17
- tzinfo (~> 0.3.22)
18
- activemodel (3.0.0.rc)
19
- activesupport (= 3.0.0.rc)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.0)
19
+ activesupport (= 3.0.0)
20
20
  builder (~> 2.1.2)
21
21
  i18n (~> 0.4.1)
22
- activerecord (3.0.0.rc)
23
- activemodel (= 3.0.0.rc)
24
- activesupport (= 3.0.0.rc)
25
- arel (~> 0.4.0)
26
- tzinfo (~> 0.3.22)
27
- activeresource (3.0.0.rc)
28
- activemodel (= 3.0.0.rc)
29
- activesupport (= 3.0.0.rc)
30
- activesupport (3.0.0.rc)
31
- arel (0.4.0)
32
- activesupport (>= 3.0.0.beta)
22
+ activerecord (3.0.0)
23
+ activemodel (= 3.0.0)
24
+ activesupport (= 3.0.0)
25
+ arel (~> 1.0.0)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.0)
28
+ activemodel (= 3.0.0)
29
+ activesupport (= 3.0.0)
30
+ activesupport (3.0.0)
31
+ arel (1.0.1)
32
+ activesupport (~> 3.0.0)
33
33
  builder (2.1.2)
34
34
  erubis (2.6.6)
35
35
  abstract (>= 1.0.0)
@@ -43,32 +43,32 @@ GEM
43
43
  rake
44
44
  polyglot (0.3.1)
45
45
  rack (1.2.1)
46
- rack-mount (0.6.9)
46
+ rack-mount (0.6.13)
47
47
  rack (>= 1.0.0)
48
48
  rack-test (0.5.4)
49
49
  rack (>= 1.0)
50
- rails (3.0.0.rc)
51
- actionmailer (= 3.0.0.rc)
52
- actionpack (= 3.0.0.rc)
53
- activerecord (= 3.0.0.rc)
54
- activeresource (= 3.0.0.rc)
55
- activesupport (= 3.0.0.rc)
56
- bundler (>= 1.0.0.rc.1)
57
- railties (= 3.0.0.rc)
58
- railties (3.0.0.rc)
59
- actionpack (= 3.0.0.rc)
60
- activesupport (= 3.0.0.rc)
61
- rake (>= 0.8.3)
50
+ rails (3.0.0)
51
+ actionmailer (= 3.0.0)
52
+ actionpack (= 3.0.0)
53
+ activerecord (= 3.0.0)
54
+ activeresource (= 3.0.0)
55
+ activesupport (= 3.0.0)
56
+ bundler (~> 1.0.0)
57
+ railties (= 3.0.0)
58
+ railties (3.0.0)
59
+ actionpack (= 3.0.0)
60
+ activesupport (= 3.0.0)
61
+ rake (>= 0.8.4)
62
62
  thor (~> 0.14.0)
63
63
  rake (0.8.7)
64
64
  thor (0.14.0)
65
65
  treetop (1.4.8)
66
66
  polyglot (>= 0.3.1)
67
- tzinfo (0.3.22)
67
+ tzinfo (0.3.23)
68
68
 
69
69
  PLATFORMS
70
70
  ruby
71
71
 
72
72
  DEPENDENCIES
73
73
  mocha
74
- rails (= 3.0.0.rc)
74
+ rails (= 3.0.0)
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://github.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.0.0
1
+ 1.1.4
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.0.0"
8
+ s.version = "1.1.4"
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
- 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}
12
+ s.date = %q{2011-04-08}
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",
data/init.rb CHANGED
@@ -1 +1 @@
1
- require 'dynamic_form'
1
+ require 'dynamic_form'
@@ -212,7 +212,7 @@ module ActionView
212
212
  end
213
213
  options[:object_name] ||= params.first
214
214
 
215
- I18n.with_options :locale => options[:locale], :scope => [:errors, :template] do |locale|
215
+ I18n.with_options :locale => options[:locale], :scope => [:activerecord, :errors, :template] do |locale|
216
216
  header_message = if options.include?(:header_message)
217
217
  options[:header_message]
218
218
  else
@@ -1,8 +1,9 @@
1
1
  en:
2
- errors:
3
- template:
4
- header:
5
- one: "1 error prohibited this %{model} from being saved"
6
- other: "%{count} errors prohibited this %{model} from being saved"
7
- # The variable :count is also available
8
- body: "There were problems with the following fields:"
2
+ activerecord:
3
+ errors:
4
+ template:
5
+ header:
6
+ one: "1 error prohibited this %{model} from being saved"
7
+ other: "%{count} errors prohibited this %{model} from being saved"
8
+ # The variable :count is also available
9
+ body: "There were problems with the following fields:"
@@ -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'
@@ -0,0 +1,4 @@
1
+ en:
2
+ errors:
3
+ # The default format to use in full dynamic error messages.
4
+ dynamic_format: "%{message}"
data/lib/dynamic_form.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "active_model/dynamic_errors"
1
2
  require 'action_view/helpers/dynamic_form'
2
3
 
3
4
  class ActionView::Base
@@ -16,27 +16,27 @@ class DynamicFormI18nTest < Test::Unit::TestCase
16
16
 
17
17
  stubs(:content_tag).returns 'content_tag'
18
18
 
19
- I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
20
- I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).returns 'There were problems with the following fields:'
19
+ I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
20
+ I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
21
21
  end
22
22
 
23
23
  def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message
24
- I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').never
24
+ I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never
25
25
  error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en')
26
26
  end
27
27
 
28
28
  def test_error_messages_for_given_no_header_option_it_translates_header_message
29
- I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').returns 'header message'
29
+ I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns 'header message'
30
30
  error_messages_for(:object => @object, :locale => 'en')
31
31
  end
32
32
 
33
33
  def test_error_messages_for_given_a_message_option_it_does_not_translate_message
34
- I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).never
34
+ I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).never
35
35
  error_messages_for(:object => @object, :message => 'message', :locale => 'en')
36
36
  end
37
37
 
38
38
  def test_error_messages_for_given_no_message_option_it_translates_message
39
- I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).returns 'There were problems with the following fields:'
39
+ I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
40
40
  error_messages_for(:object => @object, :locale => 'en')
41
41
  end
42
42
  end
@@ -166,7 +166,7 @@ class DynamicFormTest < ActionView::TestCase
166
166
 
167
167
  def test_form_with_string
168
168
  assert_dom_equal(
169
- %(<form accept-charset="UTF-8" action="create" method="post"><div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
169
+ %(<form accept-charset="UTF-8" action="create" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
170
170
  form("post")
171
171
  )
172
172
 
@@ -179,7 +179,7 @@ class DynamicFormTest < ActionView::TestCase
179
179
  end
180
180
 
181
181
  assert_dom_equal(
182
- %(<form accept-charset="UTF-8" action="update/1" method="post"><div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /></div><input id="post_id" name="post[id]" type="hidden" value="1" /><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Update" /></form>),
182
+ %(<form accept-charset="UTF-8" action="update/1" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><input id="post_id" name="post[id]" type="hidden" value="1" /><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Update" /></form>),
183
183
  form("post")
184
184
  )
185
185
  end
@@ -189,14 +189,14 @@ class DynamicFormTest < ActionView::TestCase
189
189
  @request_forgery_protection_token = 'authenticity_token'
190
190
  @form_authenticity_token = '123'
191
191
  assert_dom_equal(
192
- %(<form accept-charset="UTF-8" action="create" method="post"><div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /><input type='hidden' name='authenticity_token' value='123' /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
192
+ %(<form accept-charset="UTF-8" action="create" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input type='hidden' name='authenticity_token' value='123' /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
193
193
  form("post")
194
194
  )
195
195
  end
196
196
 
197
197
  def test_form_with_method_option
198
198
  assert_dom_equal(
199
- %(<form accept-charset="UTF-8" action="create" method="get"><div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
199
+ %(<form accept-charset="UTF-8" action="create" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
200
200
  form("post", :method=>'get')
201
201
  )
202
202
  end
@@ -214,7 +214,7 @@ class DynamicFormTest < ActionView::TestCase
214
214
  end
215
215
 
216
216
  assert_dom_equal(
217
- %(<form accept-charset="UTF-8" action="create" method="post"><div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /></div><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
217
+ %(<form accept-charset="UTF-8" action="create" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
218
218
  form("post")
219
219
  )
220
220
  end
@@ -226,7 +226,7 @@ class DynamicFormTest < ActionView::TestCase
226
226
  @post.written_on = Time.gm(2004, 6, 15, 16, 30)
227
227
 
228
228
  assert_dom_equal(
229
- %(<form accept-charset="UTF-8" action="create" method="post"><div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /></div><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n &mdash; <select id="post_written_on_4i" name="post[written_on(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_written_on_5i" name="post[written_on(5i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30" selected="selected">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
229
+ %(<form accept-charset="UTF-8" action="create" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n &mdash; <select id="post_written_on_4i" name="post[written_on(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_written_on_5i" name="post[written_on(5i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30" selected="selected">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
230
230
  form("post")
231
231
  )
232
232
  end
@@ -332,7 +332,7 @@ class DynamicFormTest < ActionView::TestCase
332
332
 
333
333
  def test_form_with_string_multipart
334
334
  assert_dom_equal(
335
- %(<form accept-charset="UTF-8" action="create" enctype="multipart/form-data" method="post"><div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
335
+ %(<form accept-charset="UTF-8" action="create" enctype="multipart/form-data" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
336
336
  form("post", :multipart => true)
337
337
  )
338
338
  end
@@ -344,7 +344,7 @@ class DynamicFormTest < ActionView::TestCase
344
344
  end
345
345
 
346
346
  expected = %(<form accept-charset="UTF-8" class="post_new" method="post" action="" id="post_new">) +
347
- %(<div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /></div>) +
347
+ %(<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>) +
348
348
  %(<div class="formError">can't be empty</div>) +
349
349
  %(<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>) +
350
350
  %(</form>)
@@ -362,11 +362,17 @@ class DynamicFormTest < ActionView::TestCase
362
362
  end
363
363
 
364
364
  expected = %(<form accept-charset="UTF-8" class="post_new" method="post" action="" id="post_new">) +
365
- %(<div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /></div>) +
365
+ %(<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>) +
366
366
  %(<div class="formError">can't be empty</div>) +
367
367
  %(<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>) +
368
368
  %(</form>)
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
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_form
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
- - 0
8
- - 0
9
- version: 1.0.0
8
+ - 1
9
+ - 4
10
+ version: 1.1.4
10
11
  platform: ruby
11
12
  authors:
12
13
  - Joel Moss
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-09 00:00:00 +01:00
18
+ date: 2011-04-08 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,32 +26,34 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 0
30
32
  version: "0"
31
33
  type: :development
32
34
  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
35
+ 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
36
  email: joel@developwithstyle.com
35
37
  executables: []
36
38
 
37
39
  extensions: []
38
40
 
39
41
  extra_rdoc_files:
40
- - README
42
+ - README.md
41
43
  files:
42
44
  - .gitignore
43
45
  - Gemfile
44
46
  - Gemfile.lock
45
47
  - MIT-LICENSE
46
- - README
48
+ - README.md
47
49
  - Rakefile
48
50
  - VERSION
49
- - dynamic-form.gemspec
50
51
  - dynamic_form.gemspec
51
52
  - init.rb
52
53
  - lib/action_view/helpers/dynamic_form.rb
53
54
  - lib/action_view/locale/en.yml
55
+ - lib/active_model/dynamic_errors.rb
56
+ - lib/active_model/locale/en.yml
54
57
  - lib/dynamic_form.rb
55
58
  - test/dynamic_form_i18n_test.rb
56
59
  - test/dynamic_form_test.rb
@@ -69,6 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
72
  requirements:
70
73
  - - ">="
71
74
  - !ruby/object:Gem::Version
75
+ hash: 3
72
76
  segments:
73
77
  - 0
74
78
  version: "0"
@@ -77,6 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
81
  requirements:
78
82
  - - ">="
79
83
  - !ruby/object:Gem::Version
84
+ hash: 3
80
85
  segments:
81
86
  - 0
82
87
  version: "0"
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
-