active_scaffold 3.6.0.pre → 3.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/{CHANGELOG → CHANGELOG.rdoc} +39 -0
  3. data/app/assets/javascripts/active_scaffold.js.erb +0 -1
  4. data/app/assets/javascripts/jquery/active_scaffold.js +35 -4
  5. data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
  6. data/app/assets/stylesheets/active_scaffold_layout.css +52 -29
  7. data/app/views/active_scaffold_overrides/_list_header.html.erb +5 -7
  8. data/app/views/active_scaffold_overrides/_list_record.html.erb +4 -5
  9. data/app/views/active_scaffold_overrides/_list_with_header.html.erb +1 -1
  10. data/app/views/active_scaffold_overrides/_refresh_list.js.erb +4 -0
  11. data/config/locales/de.yml +2 -1
  12. data/config/locales/en.yml +1 -0
  13. data/config/locales/es.yml +1 -0
  14. data/config/locales/fr.yml +2 -1
  15. data/config/locales/hu.yml +1 -0
  16. data/config/locales/ja.yml +1 -0
  17. data/config/locales/ru.yml +1 -0
  18. data/lib/active_scaffold.rb +8 -3
  19. data/lib/active_scaffold/actions/common_search.rb +11 -8
  20. data/lib/active_scaffold/actions/core.rb +79 -51
  21. data/lib/active_scaffold/actions/create.rb +27 -27
  22. data/lib/active_scaffold/actions/delete.rb +1 -1
  23. data/lib/active_scaffold/actions/field_search.rb +52 -42
  24. data/lib/active_scaffold/actions/list.rb +106 -23
  25. data/lib/active_scaffold/actions/nested.rb +59 -42
  26. data/lib/active_scaffold/actions/show.rb +3 -3
  27. data/lib/active_scaffold/actions/subform.rb +9 -16
  28. data/lib/active_scaffold/actions/update.rb +95 -77
  29. data/lib/active_scaffold/attribute_params.rb +93 -68
  30. data/lib/active_scaffold/bridges/active_storage.rb +6 -0
  31. data/lib/active_scaffold/bridges/active_storage/active_storage_bridge.rb +33 -0
  32. data/lib/active_scaffold/bridges/active_storage/active_storage_helpers.rb +54 -0
  33. data/lib/active_scaffold/bridges/active_storage/form_ui.rb +22 -0
  34. data/lib/active_scaffold/bridges/active_storage/list_ui.rb +36 -0
  35. data/lib/active_scaffold/bridges/bitfields.rb +1 -0
  36. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -15
  37. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +6 -0
  38. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +2 -2
  39. data/lib/active_scaffold/bridges/date_picker/helper.rb +46 -41
  40. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +1 -1
  41. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +2 -2
  42. data/lib/active_scaffold/bridges/file_column/form_ui.rb +3 -3
  43. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +3 -1
  44. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +2 -2
  45. data/lib/active_scaffold/bridges/record_select/helpers.rb +3 -7
  46. data/lib/active_scaffold/bridges/shared/date_bridge.rb +19 -18
  47. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -1
  48. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +20 -3
  49. data/lib/active_scaffold/config/base.rb +58 -34
  50. data/lib/active_scaffold/config/core.rb +31 -12
  51. data/lib/active_scaffold/config/delete.rb +12 -1
  52. data/lib/active_scaffold/config/list.rb +17 -7
  53. data/lib/active_scaffold/config/mark.rb +1 -1
  54. data/lib/active_scaffold/configurable.rb +5 -3
  55. data/lib/active_scaffold/constraints.rb +21 -19
  56. data/lib/active_scaffold/core.rb +35 -26
  57. data/lib/active_scaffold/data_structures/action_columns.rb +1 -1
  58. data/lib/active_scaffold/data_structures/action_link.rb +34 -16
  59. data/lib/active_scaffold/data_structures/action_links.rb +9 -11
  60. data/lib/active_scaffold/data_structures/association/abstract.rb +35 -13
  61. data/lib/active_scaffold/data_structures/association/active_mongoid.rb +2 -6
  62. data/lib/active_scaffold/data_structures/association/active_record.rb +5 -1
  63. data/lib/active_scaffold/data_structures/association/mongoid.rb +0 -3
  64. data/lib/active_scaffold/data_structures/column.rb +49 -58
  65. data/lib/active_scaffold/data_structures/columns.rb +3 -2
  66. data/lib/active_scaffold/data_structures/nested_info.rb +20 -18
  67. data/lib/active_scaffold/data_structures/sorting.rb +5 -0
  68. data/lib/active_scaffold/delayed_setup.rb +16 -6
  69. data/lib/active_scaffold/extensions/action_controller_rendering.rb +1 -1
  70. data/lib/active_scaffold/extensions/action_view_rendering.rb +34 -14
  71. data/lib/active_scaffold/extensions/cow_proxy.rb +50 -2
  72. data/lib/active_scaffold/extensions/localize.rb +3 -1
  73. data/lib/active_scaffold/extensions/routing_mapper.rb +2 -2
  74. data/lib/active_scaffold/extensions/to_label.rb +3 -2
  75. data/lib/active_scaffold/finder.rb +81 -46
  76. data/lib/active_scaffold/helpers/action_link_helpers.rb +47 -21
  77. data/lib/active_scaffold/helpers/association_helpers.rb +13 -11
  78. data/lib/active_scaffold/helpers/controller_helpers.rb +14 -11
  79. data/lib/active_scaffold/helpers/form_column_helpers.rb +133 -99
  80. data/lib/active_scaffold/helpers/human_condition_helpers.rb +1 -1
  81. data/lib/active_scaffold/helpers/id_helpers.rb +4 -0
  82. data/lib/active_scaffold/helpers/list_column_helpers.rb +76 -49
  83. data/lib/active_scaffold/helpers/pagination_helpers.rb +2 -2
  84. data/lib/active_scaffold/helpers/search_column_helpers.rb +25 -30
  85. data/lib/active_scaffold/helpers/show_column_helpers.rb +3 -5
  86. data/lib/active_scaffold/helpers/view_helpers.rb +31 -22
  87. data/lib/active_scaffold/orm_checks.rb +2 -2
  88. data/lib/active_scaffold/paginator.rb +1 -3
  89. data/lib/active_scaffold/registry.rb +11 -0
  90. data/lib/active_scaffold/responds_to_parent.rb +6 -5
  91. data/lib/active_scaffold/tableless.rb +6 -8
  92. data/lib/active_scaffold/version.rb +1 -1
  93. data/shoulda_macros/macros.rb +3 -1
  94. data/test/bridges/paperclip_test.rb +1 -1
  95. data/test/company.rb +2 -2
  96. data/test/data_structures/action_columns_test.rb +2 -2
  97. data/test/data_structures/column_test.rb +3 -6
  98. data/test/data_structures/columns_test.rb +2 -2
  99. data/test/extensions/active_record_test.rb +4 -4
  100. data/test/extensions/routing_mapper_test.rb +2 -2
  101. data/test/helpers/list_column_helpers_test.rb +3 -1
  102. data/test/misc/active_record_permissions_test.rb +2 -2
  103. data/test/misc/attribute_params_test.rb +4 -0
  104. data/test/misc/configurable_test.rb +10 -10
  105. data/test/misc/convert_numbers_format_test.rb +4 -0
  106. data/test/mock_app/app/assets/config/manifest.js +0 -0
  107. data/test/mock_app/app/controllers/cars_controller.rb +1 -0
  108. data/test/mock_app/app/controllers/people_controller.rb +3 -1
  109. data/test/mock_app/config/application.rb +1 -0
  110. data/test/mock_app/config/routes.rb +4 -1
  111. data/test/mock_app/db/schema.rb +2 -0
  112. data/test/performance/list_cars_performance_test.rb +34 -0
  113. data/test/performance/list_people_performance_test.rb +31 -0
  114. data/test/performance_test_help.rb +3 -0
  115. data/test/test_helper.rb +2 -1
  116. metadata +22 -12
  117. data/app/assets/javascripts/prototype/rico_corner.js +0 -370
  118. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +0 -5
@@ -17,18 +17,14 @@ module ActiveScaffold::DataStructures::Association
17
17
  %i[belongs_to_record belongs_to_document].include?(@association.macro)
18
18
  end
19
19
 
20
- def has_one?
20
+ def has_one? # rubocop:disable Naming/PredicateName
21
21
  %i[has_one_record has_one_document].include?(@association.macro)
22
22
  end
23
23
 
24
- def has_many?
24
+ def has_many? # rubocop:disable Naming/PredicateName
25
25
  %i[has_many_records has_many_documents].include?(@association.macro)
26
26
  end
27
27
 
28
- def collection?
29
- %i[has_many_documents has_many_records].include?(@association.macro)
30
- end
31
-
32
28
  def table_name
33
29
  @association.klass < ActiveRecord::Base ? @association.klass.table_name : super
34
30
  end
@@ -75,7 +75,11 @@ module ActiveScaffold::DataStructures::Association
75
75
 
76
76
  def scope_values
77
77
  return {} unless @association.scope
78
- @scope_values ||= @association.klass.instance_exec(&@association.scope).values rescue {}
78
+ @scope_values ||= @association.klass.instance_exec(&@association.scope).values
79
+ rescue StandardError => e
80
+ message = "Error evaluating scope for #{@association.name} in #{@association.klass.name}:"
81
+ Rails.logger.warn "#{message}\n#{e.message}\n#{e.backtrace.join("\n")}"
82
+ {}
79
83
  end
80
84
 
81
85
  def reverse_through_match?(assoc)
@@ -1,9 +1,6 @@
1
1
  module ActiveScaffold::DataStructures::Association
2
2
  class Mongoid < Abstract
3
3
  delegate :inverse_klass, :as, :dependent, :inverse, to: :@association
4
- def collection?
5
- %i[has_many has_and_belongs_to_many].include?(@association.macro)
6
- end
7
4
 
8
5
  # polymorphic belongs_to
9
6
  def polymorphic?
@@ -9,7 +9,7 @@ module ActiveScaffold::DataStructures
9
9
  alias model active_record_class
10
10
 
11
11
  # this is the name of the getter on the ActiveRecord model. it is the only absolutely required attribute ... all others will be inferred from this name.
12
- attr_accessor :name
12
+ attr_reader :name
13
13
 
14
14
  # Whether to enable inplace editing for this column. Currently works for text columns, in the List.
15
15
  attr_reader :inplace_edit
@@ -114,16 +114,9 @@ module ActiveScaffold::DataStructures
114
114
  # supported options:
115
115
  # * for association columns
116
116
  # * :select - displays a simple <select> or a collection of checkboxes to (dis)associate records
117
- def form_ui=(value)
118
- self.list_method = nil if @list_ui.nil? && value != @form_ui
119
- @form_ui = value
120
- end
121
- attr_reader :form_ui
117
+ attr_accessor :form_ui
122
118
 
123
- def list_ui=(value)
124
- self.list_method = nil if value != @list_ui
125
- @list_ui = value
126
- end
119
+ attr_writer :list_ui
127
120
 
128
121
  def list_ui
129
122
  @list_ui || form_ui
@@ -186,10 +179,11 @@ module ActiveScaffold::DataStructures
186
179
  # a collection of associations to pre-load when finding the records on a page
187
180
  attr_reader :includes
188
181
  def includes=(value)
189
- @includes = case value
190
- when Array then value
191
- else value ? [value] : value # not convert nil to [nil]
192
- end
182
+ @includes =
183
+ case value
184
+ when Array then value
185
+ else value ? [value] : value # not convert nil to [nil]
186
+ end
193
187
  end
194
188
 
195
189
  # a collection of associations to do left join when this column is included on search
@@ -198,10 +192,11 @@ module ActiveScaffold::DataStructures
198
192
  end
199
193
 
200
194
  def search_joins=(value)
201
- @search_joins = case value
202
- when Array then value
203
- else [value] # automatically convert to an array
204
- end
195
+ @search_joins =
196
+ case value
197
+ when Array then value
198
+ else [value] # automatically convert to an array
199
+ end
205
200
  end
206
201
 
207
202
  # a collection of columns to load when eager loading is disabled, if it's nil all columns will be loaded
@@ -245,6 +240,9 @@ module ActiveScaffold::DataStructures
245
240
  @associated_number
246
241
  end
247
242
 
243
+ # what string to use to join records from plural associations
244
+ attr_accessor :association_join_text
245
+
248
246
  # whether a blank row must be shown in the subform
249
247
  cattr_accessor :show_blank_record, instance_accessor: false
250
248
  @@show_blank_record = true
@@ -304,21 +302,26 @@ module ActiveScaffold::DataStructures
304
302
  end
305
303
  end
306
304
 
305
+ # cache key to cache column info
306
+ attr_reader :cache_key
307
+
307
308
  # instantiation is handled internally through the DataStructures::Columns object
308
309
  def initialize(name, active_record_class, delegated_association = nil) #:nodoc:
309
- self.name = name.to_sym
310
+ @name = name.to_sym
310
311
  @active_record_class = active_record_class
311
312
  @column = _columns_hash[name.to_s]
312
313
  @delegated_association = delegated_association
314
+ @cache_key = [@active_record_class.name, name].compact.map(&:to_s).join('#')
313
315
  setup_association_info
314
316
 
317
+ @link = nil
315
318
  @autolink = association.present?
316
319
  @table = _table_name
317
320
  @associated_limit = self.class.associated_limit
318
321
  @associated_number = self.class.associated_number
319
322
  @show_blank_record = self.class.show_blank_record
320
323
  @send_form_on_update_column = self.class.send_form_on_update_column
321
- @actions_for_association_links = self.class.actions_for_association_links.clone if association
324
+ @actions_for_association_links = self.class.actions_for_association_links.dup if association
322
325
  @select_columns = default_select_columns
323
326
 
324
327
  @text = @column.nil? || [:string, :text, String].include?(column_type)
@@ -332,10 +335,11 @@ module ActiveScaffold::DataStructures
332
335
  @form_ui = :number
333
336
  @options = {:format => :i18n_number}
334
337
  else
335
- @form_ui = case @column.type
336
- when :boolean then :checkbox
337
- when :text then :textarea
338
- end
338
+ @form_ui =
339
+ case @column.type
340
+ when :boolean then :checkbox
341
+ when :text then :textarea
342
+ end
339
343
  end
340
344
  end
341
345
  @allow_add_existing = true
@@ -369,18 +373,23 @@ module ActiveScaffold::DataStructures
369
373
  order_weight.nonzero? ? order_weight : name.to_s <=> other.name.to_s
370
374
  end
371
375
 
376
+ def convert_to_native?
377
+ number? && options[:format] && form_ui != :number
378
+ end
379
+
372
380
  def number_to_native(value)
373
381
  return value if value.blank? || !value.is_a?(String)
374
382
  native = '.' # native ruby separator
375
383
  format = {:separator => '', :delimiter => ''}.merge! I18n.t('number.format', :default => {})
376
- specific = case options[:format]
377
- when :currency
378
- I18n.t('number.currency.format', :default => nil)
379
- when :size
380
- I18n.t('number.human.format', :default => nil)
381
- when :percentage
382
- I18n.t('number.percentage.format', :default => nil)
383
- end
384
+ specific =
385
+ case options[:format]
386
+ when :currency
387
+ I18n.t('number.currency.format', :default => nil)
388
+ when :size
389
+ I18n.t('number.human.format', :default => nil)
390
+ when :percentage
391
+ I18n.t('number.percentage.format', :default => nil)
392
+ end
384
393
  format.merge! specific unless specific.nil?
385
394
  if format[:separator].blank? || !value.include?(format[:separator]) && value.include?(native) && (format[:delimiter] != native || value !~ /\.\d{3}$/)
386
395
  value
@@ -389,27 +398,8 @@ module ActiveScaffold::DataStructures
389
398
  end
390
399
  end
391
400
 
392
- # to cache method to get value in list
393
- def list_method
394
- Rails.cache.fetch(cache_key(:list_method))
395
- end
396
-
397
- def list_method=(value)
398
- Rails.cache.write(cache_key(:list_method), value)
399
- end
400
-
401
- # cache constraints for numeric columns (get in ActiveScaffold::Helpers::FormColumnHelpers::numerical_constraints_for_column)
402
- def numerical_constraints
403
- Rails.cache.fetch(cache_key(:numerical_constraints))
404
- end
405
-
406
- def numerical_constraints=(value)
407
- Rails.cache.write(cache_key(:numerical_constraints), value)
408
- end
409
-
410
- # cache key to cache column info
411
- def cache_key(attr)
412
- [@active_record_class.name, name, attr].compact.map(&:to_s).join('#')
401
+ def default_for_empty_value
402
+ (column.null ? nil : column.default) if column
413
403
  end
414
404
 
415
405
  # the table.field name for this column, if applicable
@@ -497,11 +487,12 @@ module ActiveScaffold::DataStructures
497
487
  end
498
488
 
499
489
  def initialize_sort
500
- if column && !tableless?
501
- self.sort = {:sql => field}
502
- else
503
- self.sort = false
504
- end
490
+ self.sort =
491
+ if column && !tableless?
492
+ {:sql => field}
493
+ else
494
+ false
495
+ end
505
496
  end
506
497
 
507
498
  def initialize_search_sql
@@ -23,6 +23,7 @@ module ActiveScaffold::DataStructures
23
23
  @active_record_class = active_record_class
24
24
  @_inheritable = []
25
25
  @set = []
26
+ @sorted = nil
26
27
 
27
28
  add(*args)
28
29
  end
@@ -48,8 +49,8 @@ module ActiveScaffold::DataStructures
48
49
  column = self[association]
49
50
  raise ArgumentError, "unknown column #{association}" if column.nil?
50
51
  raise ArgumentError, "column #{association} is not an association" if column.association.nil?
51
- raise ArugmentError, "column #{association} is not singular association" unless column.association.singular?
52
- raise ArugmentError, "column #{association} is polymorphic association" if column.association.polymorphic?
52
+ raise ArgumentError, "column #{association} is not singular association" unless column.association.singular?
53
+ raise ArgumentError, "column #{association} is polymorphic association" if column.association.polymorphic?
53
54
 
54
55
  klass = column.association.klass
55
56
  columns.each do |col|
@@ -31,7 +31,7 @@ module ActiveScaffold::DataStructures
31
31
  false
32
32
  end
33
33
 
34
- def has_many?
34
+ def has_many? # rubocop:disable Naming/PredicateName
35
35
  false
36
36
  end
37
37
 
@@ -39,7 +39,7 @@ module ActiveScaffold::DataStructures
39
39
  false
40
40
  end
41
41
 
42
- def has_one?
42
+ def has_one? # rubocop:disable Naming/PredicateName
43
43
  false
44
44
  end
45
45
 
@@ -83,15 +83,17 @@ module ActiveScaffold::DataStructures
83
83
 
84
84
  # A through association with has_one or has_many as source association
85
85
  # create cannot be called in nested through associations, and not-nested through associations
86
- # unless create columns include through reflection of reverse association
86
+ # unless is through singular or create columns include through reflection of reverse association
87
87
  # e.g. customer -> networks -> firewall, reverse is firewall -> network -> customer,
88
88
  # firewall can be created if create columns include network
89
89
  def readonly_through_association?(columns)
90
90
  return false unless through_association?
91
- return true if association.through_reflection.options[:through]
92
- !association.source_reflection.belongs_to? && (
93
- !child_association || !columns.include?(child_association.through_reflection.name)
94
- )
91
+ return true if association.through_reflection.options[:through] # create not possible, too many levels
92
+ return true if association.source_reflection.options[:through] # create not possible, too many levels
93
+ return false if association.through_singular? # create allowed, AS has code for this
94
+
95
+ # create allowed only if through reflection in record to be created is included in create columns
96
+ !child_association || !columns.include?(child_association.through_reflection.name)
95
97
  end
96
98
 
97
99
  def through_association?
@@ -104,25 +106,25 @@ module ActiveScaffold::DataStructures
104
106
 
105
107
  def default_sorting(chain)
106
108
  return @default_sorting if defined? @default_sorting
107
- if association.scope.is_a?(Proc) && chain.respond_to?(:values) && chain.values[:order]
108
- @default_sorting = chain.values[:order]
109
- @default_sorting = @default_sorting.map(&:to_sql) if @default_sorting[0].is_a? Arel::Nodes::Node
110
- @default_sorting = @default_sorting.join(', ')
111
- end
109
+ return unless association.scope.is_a?(Proc) && chain.respond_to?(:values) && chain.values[:order]
110
+ @default_sorting = chain.values[:order]
111
+ @default_sorting = @default_sorting.map(&:to_sql) if @default_sorting[0].is_a? Arel::Nodes::Node
112
+ @default_sorting = @default_sorting.join(', ')
112
113
  end
113
114
 
114
115
  def to_params
115
- super.merge(:association => @association.name, :assoc_id => parent_id)
116
+ super.merge(:association => @association.name, @param_name => parent_id)
116
117
  end
117
118
 
118
119
  protected
119
120
 
120
121
  def setup_constrained_fields
121
- @constrained_fields = []
122
- @constrained_fields << Array(association.foreign_key).map(&:to_sym) unless association.belongs_to?
123
- if child_association && child_association != association
124
- @constrained_fields << child_association.name
125
- end
122
+ @constrained_fields = Array(association.foreign_key).map(&:to_sym) unless association.belongs_to?
123
+ @constrained_fields ||= []
124
+ return unless child_association && child_association != association
125
+
126
+ @constrained_fields << child_association.name
127
+ @constrained_fields << child_association.foreign_type.to_sym if child_association.polymorphic?
126
128
  end
127
129
  end
128
130
 
@@ -14,6 +14,7 @@ module ActiveScaffold::DataStructures
14
14
  @clauses = []
15
15
  @constraint_columns = []
16
16
  @model = model
17
+ @sorting_by_primary_key = false
17
18
  end
18
19
 
19
20
  def set_default_sorting
@@ -106,6 +107,10 @@ module ActiveScaffold::DataStructures
106
107
  @clauses.each { |clause| yield clause }
107
108
  end
108
109
 
110
+ def each_column
111
+ @clauses.each { |clause| yield clause[0] }
112
+ end
113
+
109
114
  # provides quick access to the first (and sometimes only) clause
110
115
  def first
111
116
  @clauses.first
@@ -11,15 +11,25 @@ module ActiveScaffold
11
11
 
12
12
  module ClassMethods
13
13
  def active_scaffold(model_id = nil, &block)
14
- @active_scaffold_delayed = proc { super(model_id, &block) }
14
+ @delayed_monitor ||= Monitor.new
15
+ @active_scaffold_delayed = proc do
16
+ begin
17
+ @_prefixes = nil # clean prefixes in case is already cached, so our local_prefixes override is picked up
18
+ super(model_id, &block)
19
+ @active_scaffold_delayed = @delayed_monitor = nil # after configuring, no need to keep proc or monitor
20
+ rescue StandardError
21
+ # clear config variable if failed, so next request tries again
22
+ @active_scaffold_config = nil
23
+ raise
24
+ end
25
+ end
15
26
  end
16
27
 
17
28
  def config_active_scaffold_delayed
18
- return unless @active_scaffold_delayed
19
- @_prefixes = nil # clean prefixes in case is already cached, so our local_prefixes override is picked up
20
- block = @active_scaffold_delayed
21
- @active_scaffold_delayed = nil
22
- block.call
29
+ @delayed_monitor&.synchronize do
30
+ # if called in same thread while running config, do nothing
31
+ @active_scaffold_delayed&.call unless @active_scaffold_config
32
+ end
23
33
  end
24
34
 
25
35
  def active_scaffold_config
@@ -8,7 +8,7 @@ module ActiveScaffold
8
8
  opts = args.any? ? args.first : {}
9
9
 
10
10
  render :partial => params[:adapter][1..-1],
11
- :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe},
11
+ :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe}, # rubocop:disable Rails/OutputSafety
12
12
  :use_full_path => true, :layout => false, :content_type => :html
13
13
  @rendering_adapter = nil # recursion control
14
14
  else
@@ -39,8 +39,12 @@ module ActiveScaffold #:nodoc:
39
39
  if args.first.is_a?(Hash) && args.first[:active_scaffold]
40
40
  render_embedded args.first
41
41
  elsif args.first == :super
42
- @_view_paths ||= lookup_context.view_paths.clone
43
- @_last_template ||= lookup_context.last_template
42
+ if @lookup_context # rails 6
43
+ @_lookup_context ||= lookup_context
44
+ else # rails < 6
45
+ @_view_paths ||= lookup_context.view_paths.clone
46
+ @_last_template ||= lookup_context.last_template
47
+ end
44
48
  parts = @virtual_path.split('/')
45
49
  template = parts.pop
46
50
  prefix = parts.join('/')
@@ -58,22 +62,34 @@ module ActiveScaffold #:nodoc:
58
62
  else
59
63
  options[:prefixes] = ['active_scaffold_overrides']
60
64
  last_view_path = File.expand_path(File.dirname(File.dirname(lookup_context.last_template.inspect)), Rails.root)
61
- lookup_context.view_paths = view_paths.drop(view_paths.find_index { |path| path.to_s == last_view_path } + 1)
65
+ new_view_paths = view_paths.drop(view_paths.find_index { |path| path.to_s == last_view_path } + 1)
66
+ if @lookup_context
67
+ @lookup_context = build_lookup_context(new_view_paths)
68
+ else
69
+ lookup_context.view_paths = new_view_paths
70
+ end
62
71
  end
63
72
  result = super options
64
- lookup_context.view_paths = @_view_paths if @_view_paths
65
- lookup_context.last_template = @_last_template if @_last_template
73
+ @lookup_context = @_lookup_context if @_lookup_context # rails 6
74
+ lookup_context.view_paths = @_view_paths if @_view_paths # rails < 6
75
+ lookup_context.last_template = @_last_template if @_last_template # rails < 6
66
76
  result
67
77
  else
68
- @_view_paths ||= lookup_context.view_paths.clone
78
+ if @lookup_context # rails 6
79
+ @_lookup_context ||= lookup_context
80
+ else # rails < 6
81
+ @_view_paths ||= lookup_context.view_paths.clone
82
+ end
69
83
  last_template = lookup_context.last_template
70
- current_view = if args[0].is_a?(Hash)
71
- {:locals => args[0][:locals], :object => args[0][:object]}
72
- else # call is render 'partial', locals_hash
73
- {:locals => args[1]}
74
- end
84
+ current_view =
85
+ if args[0].is_a?(Hash)
86
+ {locals: args[0][:locals], object: args[0][:object]}
87
+ else # call is render 'partial', locals_hash
88
+ {locals: args[1]}
89
+ end
75
90
  view_stack << current_view if current_view
76
- lookup_context.view_paths = @_view_paths # reset view_paths in case a view render :super, and then render :partial
91
+ @lookup_context = @_lookup_context if @_lookup_context # rails 6, reset lookup_context in case a view render :super, and then render :partial
92
+ lookup_context.view_paths = @_view_paths if @_view_paths # rails < 6, reset view_paths in case a view render :super, and then render :partial
77
93
  result = super
78
94
  view_stack.pop if current_view.present?
79
95
  lookup_context.last_template = last_template
@@ -114,9 +130,13 @@ module ActiveScaffold #:nodoc:
114
130
  content_tag(:div, :id => id, :class => 'active-scaffold-component', :data => {:refresh => url}) do
115
131
  # parse the ActiveRecord model name from the controller path, which
116
132
  # might be a namespaced controller (e.g., 'admin/admins')
117
- model = remote_controller.to_s.sub(%r{/.*//}, '').singularize
133
+ model = remote_controller.to_s.sub(%r{.*/}, '').singularize
118
134
  content_tag(:div, :class => 'active-scaffold-header') do
119
- content_tag :h2, link_to(options[:label] || active_scaffold_config_for(model).list.label, url, :remote => true, :class => 'load-embedded')
135
+ content_tag(:h2) do
136
+ link_label = options[:label] || active_scaffold_config_for(model).list.label
137
+ link_to(link_label, url, remote: true, class: 'load-embedded', data: {error_msg: as_(:error_500)}) <<
138
+ loading_indicator_tag(url_options)
139
+ end
120
140
  end
121
141
  end
122
142
  end