active_scaffold 3.1.20 → 3.2.0

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.
Files changed (95) hide show
  1. data/app/assets/javascripts/jquery/active_scaffold.js +4 -1
  2. data/app/assets/javascripts/prototype/active_scaffold.js +4 -1
  3. data/app/assets/stylesheets/{active_scaffold.scss~ → active_scaffold.css.scss} +5 -2
  4. data/app/assets/stylesheets/{active_scaffold_colors.scss → active_scaffold_colors.css.scss} +4 -0
  5. data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -0
  6. data/app/assets/stylesheets/active_scaffold_images.css.scss +43 -0
  7. data/lib/active_scaffold/actions/core.rb +1 -0
  8. data/lib/active_scaffold/actions/nested.rb +0 -1
  9. data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
  10. data/lib/active_scaffold/helpers/form_column_helpers.rb +1 -0
  11. data/lib/active_scaffold/version.rb +2 -2
  12. data/test/mock_app/.gitignore +2 -0
  13. metadata +86 -164
  14. data/app/assets/javascripts/active_scaffold.js.erb~ +0 -16
  15. data/app/assets/javascripts/jquery/active_scaffold.js~ +0 -1053
  16. data/app/assets/javascripts/jquery/draggable_lists.js~ +0 -27
  17. data/app/assets/javascripts/prototype/active_scaffold.js~ +0 -1037
  18. data/app/assets/stylesheets/active_scaffold.css.erb +0 -11
  19. data/app/assets/stylesheets/active_scaffold.css.erb~ +0 -11
  20. data/app/assets/stylesheets/active_scaffold.css.scss.erb~ +0 -1120
  21. data/app/assets/stylesheets/active_scaffold.css.scss~ +0 -11
  22. data/app/assets/stylesheets/active_scaffold.css~ +0 -11
  23. data/app/assets/stylesheets/active_scaffold_colors.css +0 -244
  24. data/app/assets/stylesheets/active_scaffold_colors.css.scss~ +0 -481
  25. data/app/assets/stylesheets/active_scaffold_default.css.erb +0 -47
  26. data/app/assets/stylesheets/active_scaffold_default.css.erb~ +0 -57
  27. data/app/assets/stylesheets/active_scaffold_default.css.scss~ +0 -1092
  28. data/app/assets/stylesheets/active_scaffold_default.css~ +0 -923
  29. data/app/assets/stylesheets/active_scaffold_layout.css~ +0 -922
  30. data/app/assets/stylesheets/blue-theme.css~ +0 -1150
  31. data/config/locales/es.yml~ +0 -120
  32. data/frontends/default/views/_action_group.html.erb~ +0 -24
  33. data/frontends/default/views/_base_form.html.erb~ +0 -42
  34. data/frontends/default/views/_form.html.erb~ +0 -26
  35. data/frontends/default/views/_form_association.html.erb~ +0 -19
  36. data/frontends/default/views/_form_association_footer.html.erb~ +0 -48
  37. data/frontends/default/views/_horizontal_subform.html.erb~ +0 -32
  38. data/frontends/default/views/_horizontal_subform_header.html.erb~ +0 -11
  39. data/frontends/default/views/_horizontal_subform_record.html.erb~ +0 -38
  40. data/frontends/default/views/_list_actions.html.erb~ +0 -15
  41. data/frontends/default/views/_list_inline_adapter.html.erb~ +0 -10
  42. data/frontends/default/views/_list_messages.html.erb~ +0 -30
  43. data/frontends/default/views/_list_pagination.html.erb~ +0 -11
  44. data/frontends/default/views/_list_pagination_links.html.erb~ +0 -0
  45. data/frontends/default/views/_list_with_header.html.erb~ +0 -36
  46. data/frontends/default/views/_render_field.js.erb~ +0 -23
  47. data/frontends/default/views/_row.html.erb~ +0 -6
  48. data/frontends/default/views/_show.html.erb~ +0 -8
  49. data/frontends/default/views/_update_form.html.erb~ +0 -6
  50. data/frontends/default/views/_vertical_subform.html.erb~ +0 -12
  51. data/frontends/default/views/add_existing.js.erb~ +0 -18
  52. data/frontends/default/views/add_existing_form.html.erb~ +0 -5
  53. data/frontends/default/views/create.html.erb~ +0 -5
  54. data/frontends/default/views/edit_associated.js.erb~ +0 -13
  55. data/frontends/default/views/on_create.js.erb~ +0 -45
  56. data/frontends/default/views/on_update.js.erb~ +0 -31
  57. data/frontends/default/views/render_field.js.erb~ +0 -1
  58. data/frontends/default/views/search.html.erb~ +0 -5
  59. data/frontends/default/views/show.html.erb~ +0 -5
  60. data/frontends/default/views/update.html.erb~ +0 -8
  61. data/frontends/default/views/update_column.js.erb~ +0 -16
  62. data/lib/active_scaffold.rb~ +0 -373
  63. data/lib/active_scaffold/actions/core.rb~ +0 -203
  64. data/lib/active_scaffold/actions/create.rb~ +0 -148
  65. data/lib/active_scaffold/actions/list.rb~ +0 -196
  66. data/lib/active_scaffold/actions/nested.rb~ +0 -247
  67. data/lib/active_scaffold/actions/search.rb~ +0 -49
  68. data/lib/active_scaffold/actions/subform.rb~ +0 -27
  69. data/lib/active_scaffold/actions/update.rb~ +0 -150
  70. data/lib/active_scaffold/attribute_params.rb~ +0 -203
  71. data/lib/active_scaffold/bridges/date_picker/helper.rb~ +0 -180
  72. data/lib/active_scaffold/bridges/record_select/helpers.rb~ +0 -86
  73. data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +0 -209
  74. data/lib/active_scaffold/config/base.rb~ +0 -72
  75. data/lib/active_scaffold/config/list.rb~ +0 -195
  76. data/lib/active_scaffold/config/nested.rb~ +0 -41
  77. data/lib/active_scaffold/config/search.rb~ +0 -74
  78. data/lib/active_scaffold/constraints.rb~ +0 -186
  79. data/lib/active_scaffold/data_structures/action_columns.rb~ +0 -140
  80. data/lib/active_scaffold/data_structures/action_link.rb~ +0 -179
  81. data/lib/active_scaffold/data_structures/nested_info.rb~ +0 -147
  82. data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +0 -22
  83. data/lib/active_scaffold/extensions/action_view_rendering.rb~ +0 -120
  84. data/lib/active_scaffold/extensions/active_association_reflection.rb~ +0 -22
  85. data/lib/active_scaffold/extensions/cache_association.rb~ +0 -12
  86. data/lib/active_scaffold/extensions/reverse_associations.rb~ +0 -64
  87. data/lib/active_scaffold/extensions/routing_mapper.rb~ +0 -48
  88. data/lib/active_scaffold/extensions/unsaved_associated.rb~ +0 -62
  89. data/lib/active_scaffold/finder.rb~ +0 -370
  90. data/lib/active_scaffold/helpers/controller_helpers.rb~ +0 -92
  91. data/lib/active_scaffold/helpers/form_column_helpers.rb~ +0 -320
  92. data/lib/active_scaffold/helpers/id_helpers.rb~ +0 -123
  93. data/lib/active_scaffold/helpers/list_column_helpers.rb~ +0 -370
  94. data/lib/active_scaffold/helpers/search_column_helpers.rb~ +0 -263
  95. data/lib/active_scaffold/helpers/view_helpers.rb~ +0 -350
@@ -1,147 +0,0 @@
1
- module ActiveScaffold::DataStructures
2
- class NestedInfo
3
- def self.get(model, params)
4
- nested_info = {}
5
- begin
6
- nested_info[:name] = (params[:association] || params[:named_scope]).to_sym
7
- nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize
8
- nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model
9
- nested_info[:parent_id] = params[nested_info[:parent_model].name.foreign_key]
10
- if nested_info[:parent_id]
11
- unless params[:association].nil?
12
- ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info)
13
- else
14
- ActiveScaffold::DataStructures::NestedInfoScope.new(model, nested_info)
15
- end
16
- end
17
- rescue ActiveScaffold::ControllerNotFound
18
- nil
19
- end
20
- end
21
-
22
- attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :scope
23
-
24
- def initialize(model, nested_info)
25
- @parent_model = nested_info[:parent_model]
26
- @parent_id = nested_info[:parent_id]
27
- @parent_scaffold = nested_info[:parent_scaffold]
28
- end
29
-
30
- def to_params
31
- {:parent_scaffold => parent_scaffold.controller_path}
32
- end
33
-
34
- def new_instance?
35
- result = @new_instance.nil?
36
- @new_instance = false
37
- result
38
- end
39
-
40
- def parent_scope
41
- parent_model.find(parent_id)
42
- end
43
-
44
- def habtm?
45
- false
46
- end
47
-
48
- def belongs_to?
49
- false
50
- end
51
-
52
- def has_one?
53
- false
54
- end
55
-
56
- def readonly?
57
- false
58
- end
59
-
60
- def sorted?
61
- false
62
- end
63
- end
64
-
65
- class NestedInfoAssociation < NestedInfo
66
- def initialize(model, nested_info)
67
- super(model, nested_info)
68
- @association = parent_model.reflect_on_association(nested_info[:name])
69
- iterate_model_associations(model)
70
- end
71
-
72
- def name
73
- self.association.name
74
- end
75
-
76
- def habtm?
77
- association.macro == :has_and_belongs_to_many
78
- end
79
-
80
- def belongs_to?
81
- association.belongs_to?
82
- end
83
-
84
- def has_one?
85
- association.macro == :has_one
86
- end
87
-
88
- def readonly?
89
- if association.options.has_key? :readonly
90
- association.options[:readonly]
91
- else
92
- association.options.has_key? :through
93
- end
94
- end
95
-
96
- def sorted?
97
- association.options.has_key? :order
98
- end
99
-
100
- def default_sorting
101
- association.options[:order]
102
- end
103
-
104
- def to_params
105
- super.merge(:association => @association.name, :assoc_id => parent_id)
106
- end
107
-
108
- protected
109
-
110
- def iterate_model_associations(model)
111
- @constrained_fields = []
112
- @constrained_fields << association.foreign_key.to_sym unless association.belongs_to?
113
- model.reflect_on_all_associations.each do |current|
114
- debugger
115
- if !current.belongs_to? && association.foreign_key == current.association_foreign_key
116
- constrained_fields << current.name.to_sym
117
- @child_association = current if current.klass == @parent_model
118
- end
119
- if association.foreign_key == current.foreign_key
120
- # show columns for has_many and has_one child associationes
121
- constrained_fields << current.name.to_sym if current.belongs_to?
122
- if association.options[:as] and current.options[:polymorphic]
123
- @child_association = current if association.options[:as].to_sym == current.name
124
- else
125
- @child_association = current if current.klass == @parent_model
126
- end
127
- end
128
- end
129
- end
130
- end
131
-
132
- class NestedInfoScope < NestedInfo
133
- def initialize(model, nested_info)
134
- super(model, nested_info)
135
- @scope = nested_info[:name]
136
- @constrained_fields = []
137
- end
138
-
139
- def to_params
140
- super.merge(:named_scope => @scope)
141
- end
142
-
143
- def name
144
- self.scope
145
- end
146
- end
147
- end
@@ -1,22 +0,0 @@
1
- # wrap the action rendering for ActiveScaffold controllers
2
- module ActionController #:nodoc:
3
- class Base
4
- def render_with_active_scaffold(*args, &block)
5
- if self.class.uses_active_scaffold? and params[:adapter] and @rendering_adapter.nil?
6
- @rendering_adapter = true # recursion control
7
- # if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template
8
- opts = args.blank? ? Hash.new : args.first
9
- render :partial => params[:adapter][1..-1],
10
- :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe},
11
- :use_full_path => true, :layout => false, :content_type => :html
12
- @rendering_adapter = nil # recursion control
13
- else
14
- render_without_active_scaffold(*args, &block)
15
- end
16
- end
17
- alias_method_chain :render, :active_scaffold
18
-
19
- # Rails 2.x implementation is post-initialization on :active_scaffold method
20
- end
21
- end
22
-
@@ -1,120 +0,0 @@
1
- module ActionView
2
- class LookupContext
3
- attr_accessor :uses_active_scaffold
4
- module ViewPaths
5
- def find_all_templates(name, partial = false, locals = {})
6
- prefixes.collect do |prefix|
7
- view_paths.collect do |resolver|
8
- temp_args = *args_for_lookup(name, [prefix], partial, locals)
9
- temp_args[1] = temp_args[1][0]
10
- resolver.find_all(*temp_args)
11
- end
12
- end.flatten!
13
- end
14
- end
15
-
16
- # Overload formats= to expand ["*/*"] values and automatically
17
- # add :html as fallback to :js.
18
- def formats=(values)
19
- debugger
20
- if values == [:js] && uses_active_scaffold
21
- _set_detail(:formats, values) if values != @details[:formats]
22
- else
23
- super(values)
24
- end
25
- end
26
- end
27
- end
28
-
29
- # wrap the action rendering for ActiveScaffold views
30
- module ActionView::Helpers #:nodoc:
31
- module RenderingHelper
32
- #
33
- # Adds two rendering options.
34
- #
35
- # ==render :super
36
- #
37
- # This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates.
38
- # Useful if you want to wrap an existing template. Just call super!
39
- #
40
- # ==render :active_scaffold => #{controller.to_s}, options = {}+
41
- #
42
- # Lets you embed an ActiveScaffold by referencing the controller where it's configured.
43
- #
44
- # You may specify options[:constraints] for the embedded scaffold. These constraints have three effects:
45
- # * the scaffold's only displays records matching the constraint
46
- # * all new records created will be assigned the constrained values
47
- # * constrained columns will be hidden (they're pretty boring at this point)
48
- #
49
- # You may also specify options[:conditions] for the embedded scaffold. These only do 1/3 of what
50
- # constraints do (they only limit search results). Any format accepted by ActiveRecord::Base.find is valid.
51
- #
52
- # Defining options[:label] lets you completely customize the list title for the embedded scaffold.
53
- #
54
- def render_with_active_scaffold(*args, &block)
55
- if args.first == :super
56
- last_view = view_stack.last || {:view => instance_variable_get(:@virtual_path).split('/').last}
57
- options = args[1] || {}
58
- options[:locals] ||= {}
59
- options[:locals].reverse_merge!(last_view[:locals] || {})
60
- if last_view[:templates].nil?
61
- last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals].keys)
62
- last_view[:templates].shift
63
- end
64
- options[:template] = last_view[:templates].shift
65
- view_stack << last_view
66
- result = render_without_active_scaffold options
67
- view_stack.pop
68
- result
69
- elsif args.first.is_a? Hash and args.first[:active_scaffold]
70
- require 'digest/md5'
71
- options = args.first
72
-
73
- remote_controller = options[:active_scaffold]
74
- constraints = options[:constraints]
75
- conditions = options[:conditions]
76
- eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s)
77
- session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}}
78
- options[:params] ||= {}
79
- options[:params].merge! :eid => eid, :embedded => true
80
-
81
- id = "as_#{eid}-embedded"
82
- url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params])
83
-
84
- if controller.respond_to?(:render_component_into_view)
85
- controller.send(:render_component_into_view, url_options)
86
- else
87
- content_tag(:div, :id => id, :class => 'active-scaffold-component') do
88
- url = url_for(url_options)
89
- content_tag(:div, :class => 'active-scaffold-header') do
90
- content_tag :h2, link_to(args.first[:label] || active_scaffold_config_for(remote_controller.to_s.singularize).list.label, url, :remote => true)
91
- end <<
92
- if ActiveScaffold.js_framework == :prototype
93
- javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});")
94
- elsif ActiveScaffold.js_framework == :jquery
95
- javascript_tag("$('##{id}').load('#{url}');")
96
- end
97
- end
98
- end
99
-
100
- else
101
- options = args.first
102
- if options.is_a?(Hash)
103
- current_view = {:view => options[:partial], :partial => true} if options[:partial]
104
- current_view = {:view => options[:template], :partial => false} if current_view.nil? && options[:template]
105
- current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals]
106
- view_stack << current_view if current_view.present?
107
- end
108
- result = render_without_active_scaffold(*args, &block)
109
- view_stack.pop if current_view.present?
110
- result
111
- end
112
- end
113
- alias_method_chain :render, :active_scaffold
114
-
115
- def view_stack
116
- @_view_stack ||= []
117
- end
118
-
119
- end
120
- end
@@ -1,22 +0,0 @@
1
- # Bugfix: building an sti model from an association fails
2
- # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6306-collection-associations-build-method-not-supported-for-sti
3
- # https://github.com/rails/rails/issues/815
4
- # https://github.com/rails/rails/pull/1686
5
- ActiveRecord::Reflection::AssociationReflection.class_eval do
6
- def klass_with_sti(*opts)
7
- sti_col = klass.inheritance_column
8
- if (h = opts.first).is_a? Hash and (passed_type = ( h[sti_col] || h[sti_col.to_sym] )) and (new_klass = active_record.send(:compute_type, passed_type)) < klass
9
- new_klass
10
- else
11
- klass
12
- end
13
- end
14
- def build_association(*opts, &block)
15
- self.original_build_association_called = true
16
- klass_with_sti(*opts).new(*opts, &block)
17
- end
18
- def create_association(*opts, &block)
19
- self.original_build_association_called = true
20
- klass_with_sti(*opts).create(*opts, &block)
21
- end
22
- end
@@ -1,12 +0,0 @@
1
- module ActiveRecord
2
- class Relation
3
- def target=(records)
4
- debugger
5
- @loaded = true
6
- @records = records
7
- puts loaded?.inspect
8
- puts self.object_id
9
- @records
10
- end
11
- end
12
- end
@@ -1,64 +0,0 @@
1
- module ActiveRecord
2
- module Reflection
3
- class AssociationReflection #:nodoc:
4
- def inverse_for?(klass)
5
- inverse_class = self.klass unless options[:polymorphic]
6
- inverse_class.present? && (inverse_class == klass || klass < inverse_class)
7
- end
8
-
9
- attr_writer :reverse
10
- def reverse
11
- @reverse ||= inverse_of.try(:name)
12
- end
13
-
14
- def inverse_of_with_autodetect
15
- inverse_of_without_autodetect || autodetect_inverse
16
- end
17
- alias_method_chain :inverse_of, :autodetect
18
-
19
- protected
20
-
21
- def autodetect_inverse
22
- return nil if options[:polymorphic]
23
- reverse_matches = []
24
-
25
- # stage 1 filter: collect associations that point back to this model and use the same foreign_key
26
- klass.reflect_on_all_associations.each do |assoc|
27
- if self.options[:through]
28
- # only iterate has_many :through associations
29
- next unless assoc.options[:through]
30
- next unless assoc.through_reflection.klass == self.through_reflection.klass
31
- else
32
- # skip over has_many :through associations
33
- next if assoc.options[:through]
34
- next unless assoc.options[:polymorphic] or assoc.class_name.constantize == self.active_record
35
-
36
- case [assoc.macro, self.macro].find_all{|m| m == :has_and_belongs_to_many}.length
37
- # if both are a habtm, then match them based on the join table
38
- when 2
39
- next unless assoc.options[:join_table] == self.options[:join_table]
40
-
41
- # if only one is a habtm, they do not match
42
- when 1
43
- next
44
-
45
- # otherwise, match them based on the foreign_key
46
- when 0
47
- next unless assoc.foreign_key.to_sym == self.foreign_key.to_sym
48
- end
49
- end
50
-
51
- reverse_matches << assoc
52
- end
53
-
54
- # stage 2 filter: name-based matching (association name vs self.active_record.to_s)
55
- reverse_matches.find_all do |assoc|
56
- self.active_record.to_s.underscore.include? assoc.name.to_s.pluralize.singularize
57
- end if reverse_matches.length > 1
58
-
59
- reverse_matches.first
60
- end
61
-
62
- end
63
- end
64
- end
@@ -1,48 +0,0 @@
1
- module ActionDispatch
2
- module Routing
3
- ACTIVE_SCAFFOLD_CORE_ROUTING = {
4
- :collection => {:show_search => :get, :render_field => :get},
5
- :member => {:row => :get, :update_column => :post, :render_field => :get}
6
- }
7
- ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = {
8
- :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post},
9
- :member => {:edit_associated => :get, :add_association => :get, :destroy_existing => :delete}
10
- }
11
- class Mapper
12
- module Base
13
- def as_routes(options = {:association => true})
14
- collection do
15
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each {|name, type| send(type, name)}
16
- end
17
- member do
18
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each {|name, type| send(type, name)}
19
- end
20
- as_association_routes if options[:association]
21
- end
22
-
23
- def as_association_routes
24
- collection do
25
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each {|name, type| send(type, name)}
26
- end
27
- member do
28
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each {|name, type| send(type, name)}
29
- end
30
- end
31
-
32
- def as_nested_resources(*resources)
33
- options = resources.extract_options!
34
- resources.each do |resource|
35
- resources(resource, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :association => resource)) { yield if block_given? }
36
- end
37
- end
38
-
39
- def as_scoped_routes(*scopes)
40
- options = scopes.extract_options!
41
- scopes.each do |scope|
42
- resources(parent_resource.plural, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :named_scope => scope, :as => :scope)) { yield if block_given? }
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,62 +0,0 @@
1
- # save and validation support for associations.
2
- class ActiveRecord::Base
3
- def associated_valid?(path = [])
4
- return true if path.include?(self) # prevent recursion (if associated and parent are new records)
5
- path << self
6
- # using [].all? syntax to avoid a short-circuit
7
- with_unsaved_associated { |a| debugger; [a.valid?, a.associated_valid?(path)].all? {|v| v == true} }
8
- end
9
-
10
- def save_associated
11
- with_unsaved_associated { |a| a.save and a.save_associated }
12
- end
13
-
14
- def save_associated!
15
- save_associated or raise(ActiveRecord::RecordNotSaved)
16
- end
17
-
18
- def no_errors_in_associated?
19
- with_unsaved_associated {|a| a.errors.count == 0 and a.no_errors_in_associated?}
20
- end
21
-
22
- protected
23
-
24
- # Provide an override to allow the model to restrict which associations are considered
25
- # by ActiveScaffolds update mechanism. This allows the model to restrict things like
26
- # Acts-As-Versioned versions associations being traversed.
27
- #
28
- # By defining the method :scaffold_update_nofollow returning an array of associations
29
- # these associations will not be traversed.
30
- # By defining the method :scaffold_update_follow returning an array of associations,
31
- # only those associations will be traversed.
32
- #
33
- # Otherwise the default behaviour of traversing all associations will be preserved.
34
- def associations_for_update
35
- if self.respond_to?( :scaffold_update_nofollow )
36
- self.class.reflect_on_all_associations.reject { |association| self.scaffold_update_nofollow.include?( association.name ) }
37
- elsif self.respond_to?( :scaffold_update_follow )
38
- self.class.reflect_on_all_associations.select { |association| self.scaffold_update_follow.include?( association.name ) }
39
- else
40
- self.class.reflect_on_all_associations
41
- end
42
- end
43
-
44
- private
45
-
46
- # yields every associated object that has been instantiated and is flagged as unsaved.
47
- # returns false if any yield returns false.
48
- # returns true otherwise, even when none of the associations have been instantiated. build wrapper methods accordingly.
49
- def with_unsaved_associated
50
- associations_for_update.all? do |association|
51
- association_proxy = send(association.name)
52
- if association_proxy
53
- records = association_proxy
54
- records = [records] unless records.is_a? Array # convert singular associations into collections for ease of use
55
- debugger
56
- records.select {|r| r.unsaved? and not r.readonly?}.all? {|r| yield r} # must use select instead of find_all, which Rails overrides on association proxies for db access
57
- else
58
- true
59
- end
60
- end
61
- end
62
- end