bbenezech-nested_form 0.0.5 → 0.0.6

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.
@@ -1,3 +1,13 @@
1
+ 0.0.6
2
+
3
+ Index blueprint by full name instead of just association name.
4
+ This was a design flaw:
5
+ A -> B
6
+ A -> C
7
+ B -> D
8
+ C -> D
9
+ When editing A, adding a D in C, B's D would show up instead, with name pointing to B.
10
+
1
11
  0.0.5
2
12
 
3
13
  JS update (id generation)
@@ -14,14 +14,17 @@ module NestedForm
14
14
  def link_to_add(*args, &block)
15
15
  options = args.extract_options!.symbolize_keys
16
16
  association = args.pop
17
+ parent_names = (object_name.scan(/([a-z_]+_attributes)/)).flatten
18
+ blueprint_name = (parent_names << association).join('_') + '_fields_blueprint'
17
19
  options[:class] = [options[:class], "add_nested_fields"].compact.join(" ")
18
20
  options["data-association"] = association
21
+ options["data-blueprint_name"] = blueprint_name
19
22
  args << (options.delete(:href) || "javascript:void(0)")
20
23
  args << options
21
24
  @fields ||= {}
22
- @template.after_nested_form(association) do
25
+ @template.after_nested_form(blueprint_name) do
23
26
  model_object = object.class.reflect_on_association(association).klass.new
24
- output = %Q[<div id="#{association}_fields_blueprint" style="display: none" class="fields_blueprint">].html_safe
27
+ output = %Q[<div id="#{blueprint_name}" style="display:none" class="fields_blueprint">].html_safe
25
28
  output << fields_for(association, model_object, :child_index => "new_#{association}", &@fields[association])
26
29
  output.safe_concat('</div>')
27
30
  output
@@ -21,11 +21,11 @@ module NestedForm
21
21
  end
22
22
  end
23
23
 
24
- def after_nested_form(association, &block)
24
+ def after_nested_form(blueprint_name, &block)
25
25
  @associations ||= []
26
26
  @after_nested_form_callbacks ||= []
27
- unless @associations.include?(association)
28
- @associations << association
27
+ unless @associations.include?(blueprint_name)
28
+ @associations << blueprint_name
29
29
  @after_nested_form_callbacks << block
30
30
  end
31
31
  end
@@ -7,10 +7,10 @@ jQuery(function($) {
7
7
  NestedFormEvents.prototype = {
8
8
  addFields: function(e) {
9
9
  // Setup
10
- var link = e.currentTarget;
11
- var assoc = $(link).attr('data-association'); // Name of child
12
- var content = $('#' + assoc + '_fields_blueprint').html(); // Fields template
13
-
10
+ var link = e.currentTarget;
11
+ var assoc = $(link).attr('data-association'); // Name of child
12
+ var blueprint_name = $(link).attr('data-blueprint_name'); // Blueprint name/id for that association
13
+ var content = $('#' + blueprint_name).html(); // Fields template
14
14
  // Make a unique ID for the new child
15
15
  var regexp = new RegExp('new_' + assoc, 'g');
16
16
  var new_id = new Date().getTime();
@@ -7,10 +7,10 @@ jQuery(function($) {
7
7
  NestedFormEvents.prototype = {
8
8
  addFields: function(e) {
9
9
  // Setup
10
- var link = e.currentTarget;
11
- var assoc = $(link).attr('data-association'); // Name of child
12
- var content = $('#' + assoc + '_fields_blueprint').html(); // Fields template
13
-
10
+ var link = e.currentTarget;
11
+ var assoc = $(link).attr('data-association'); // Name of child
12
+ var blueprint_name = $(link).attr('data-blueprint_name'); // Blueprint name/id for that association
13
+ var content = $('#' + blueprint_name).html(); // Fields template
14
14
  // Make a unique ID for the new child
15
15
  var regexp = new RegExp('new_' + assoc, 'g');
16
16
  var new_id = new Date().getTime();
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbenezech-nested_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-02-22 00:00:00.000000000 Z
13
+ date: 2012-03-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec-rails
17
- requirement: &70169599342280 !ruby/object:Gem::Requirement
17
+ requirement: &70268850811300 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.6.0
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70169599342280
25
+ version_requirements: *70268850811300
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mocha
28
- requirement: &70169599338560 !ruby/object:Gem::Requirement
28
+ requirement: &70268850810140 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,9 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70169599338560
36
+ version_requirements: *70268850810140
37
37
  description: Gem to conveniently handle multiple models in a single form with Rails
38
- 3 and jQuery or Prototype. Version maintained by fxposter.
38
+ 3 and jQuery or Prototype. Version maintained by fxposter, with some patches aimed
39
+ at RailsAdmin.
39
40
  email: ryan@railscasts.com
40
41
  executables: []
41
42
  extensions: []
@@ -124,5 +125,5 @@ rubygems_version: 1.8.11
124
125
  signing_key:
125
126
  specification_version: 3
126
127
  summary: Gem to conveniently handle multiple models in a single form. Version maintained
127
- by fxposter.
128
+ by fxposter, with some patches aimed at RailsAdmin.
128
129
  test_files: []