active_scaffold 3.5.5 → 3.6.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +18 -2
  3. data/README.md +17 -7
  4. data/app/assets/javascripts/jquery/active_scaffold.js +28 -2
  5. data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -2
  6. data/app/views/active_scaffold_overrides/_form.html.erb +1 -1
  7. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +3 -2
  8. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +6 -6
  9. data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
  10. data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
  11. data/app/views/active_scaffold_overrides/_list.html.erb +2 -1
  12. data/app/views/active_scaffold_overrides/_list_messages.html.erb +1 -0
  13. data/app/views/active_scaffold_overrides/_messages.html.erb +1 -0
  14. data/app/views/active_scaffold_overrides/_render_field.js.erb +2 -1
  15. data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +2 -1
  16. data/app/views/active_scaffold_overrides/_show_columns.html.erb +2 -2
  17. data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +4 -4
  18. data/app/views/active_scaffold_overrides/_update_calculations.js.erb +1 -1
  19. data/app/views/active_scaffold_overrides/_update_column.js.erb +2 -2
  20. data/app/views/active_scaffold_overrides/action_confirmation.html.erb +2 -2
  21. data/app/views/active_scaffold_overrides/delete.html.erb +2 -2
  22. data/app/views/active_scaffold_overrides/on_action_update.js.erb +16 -6
  23. data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
  24. data/app/views/active_scaffold_overrides/row.js.erb +1 -1
  25. data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
  26. data/lib/active_scaffold.rb +11 -13
  27. data/lib/active_scaffold/actions/core.rb +25 -35
  28. data/lib/active_scaffold/actions/create.rb +1 -1
  29. data/lib/active_scaffold/actions/delete.rb +2 -2
  30. data/lib/active_scaffold/actions/field_search.rb +2 -2
  31. data/lib/active_scaffold/actions/list.rb +8 -7
  32. data/lib/active_scaffold/actions/nested.rb +9 -9
  33. data/lib/active_scaffold/actions/search.rb +1 -1
  34. data/lib/active_scaffold/actions/show.rb +1 -1
  35. data/lib/active_scaffold/actions/subform.rb +3 -1
  36. data/lib/active_scaffold/actions/update.rb +5 -4
  37. data/lib/active_scaffold/active_record_permissions.rb +2 -11
  38. data/lib/active_scaffold/attribute_params.rb +16 -23
  39. data/lib/active_scaffold/bridges.rb +8 -8
  40. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +1 -1
  41. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +1 -1
  42. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +3 -18
  43. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +1 -1
  44. data/lib/active_scaffold/bridges/chosen/helpers.rb +7 -6
  45. data/lib/active_scaffold/bridges/date_picker/ext.rb +0 -13
  46. data/lib/active_scaffold/bridges/date_picker/helper.rb +3 -3
  47. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +1 -1
  48. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +3 -3
  49. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +8 -7
  50. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -4
  51. data/lib/active_scaffold/bridges/paper_trail.rb +1 -1
  52. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
  53. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
  54. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +2 -2
  55. data/lib/active_scaffold/bridges/record_select/helpers.rb +9 -9
  56. data/lib/active_scaffold/bridges/shared/date_bridge.rb +3 -3
  57. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +1 -1
  58. data/lib/active_scaffold/config/base.rb +89 -21
  59. data/lib/active_scaffold/config/core.rb +127 -18
  60. data/lib/active_scaffold/config/delete.rb +2 -0
  61. data/lib/active_scaffold/config/field_search.rb +7 -1
  62. data/lib/active_scaffold/config/form.rb +10 -1
  63. data/lib/active_scaffold/config/list.rb +27 -11
  64. data/lib/active_scaffold/config/mark.rb +3 -1
  65. data/lib/active_scaffold/config/nested.rb +16 -17
  66. data/lib/active_scaffold/config/search.rb +9 -0
  67. data/lib/active_scaffold/config/show.rb +4 -0
  68. data/lib/active_scaffold/config/update.rb +4 -0
  69. data/lib/active_scaffold/configurable.rb +11 -6
  70. data/lib/active_scaffold/constraints.rb +1 -1
  71. data/lib/active_scaffold/core.rb +46 -16
  72. data/lib/active_scaffold/data_structures/action_columns.rb +50 -59
  73. data/lib/active_scaffold/data_structures/action_link.rb +20 -8
  74. data/lib/active_scaffold/data_structures/action_links.rb +6 -2
  75. data/lib/active_scaffold/data_structures/association/abstract.rb +9 -5
  76. data/lib/active_scaffold/data_structures/association/active_record.rb +1 -1
  77. data/lib/active_scaffold/data_structures/column.rb +51 -33
  78. data/lib/active_scaffold/data_structures/nested_info.rb +1 -1
  79. data/lib/active_scaffold/data_structures/set.rb +8 -0
  80. data/lib/active_scaffold/data_structures/sorting.rb +5 -2
  81. data/lib/active_scaffold/delayed_setup.rb +2 -1
  82. data/lib/active_scaffold/extensions/action_controller_rendering.rb +2 -1
  83. data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
  84. data/lib/active_scaffold/extensions/cow_proxy.rb +43 -0
  85. data/lib/active_scaffold/extensions/ice_nine.rb +36 -0
  86. data/lib/active_scaffold/extensions/left_outer_joins.rb +8 -33
  87. data/lib/active_scaffold/extensions/routing_mapper.rb +4 -43
  88. data/lib/active_scaffold/extensions/unsaved_record.rb +2 -4
  89. data/lib/active_scaffold/finder.rb +26 -30
  90. data/lib/active_scaffold/helpers/action_link_helpers.rb +16 -16
  91. data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
  92. data/lib/active_scaffold/helpers/controller_helpers.rb +11 -1
  93. data/lib/active_scaffold/helpers/form_column_helpers.rb +25 -24
  94. data/lib/active_scaffold/helpers/id_helpers.rb +2 -2
  95. data/lib/active_scaffold/helpers/list_column_helpers.rb +8 -6
  96. data/lib/active_scaffold/helpers/search_column_helpers.rb +4 -4
  97. data/lib/active_scaffold/helpers/view_helpers.rb +7 -13
  98. data/lib/active_scaffold/marked_model.rb +2 -2
  99. data/lib/active_scaffold/orm_checks.rb +1 -5
  100. data/lib/active_scaffold/paginator.rb +6 -4
  101. data/lib/active_scaffold/registry.rb +22 -0
  102. data/lib/active_scaffold/responds_to_parent.rb +2 -6
  103. data/lib/active_scaffold/tableless.rb +63 -59
  104. data/lib/active_scaffold/version.rb +2 -2
  105. data/lib/generators/active_scaffold/controller_generator.rb +2 -2
  106. data/lib/generators/active_scaffold/install_generator.rb +1 -1
  107. data/lib/generators/active_scaffold/resource_generator.rb +2 -2
  108. data/test/bridges/date_picker_test.rb +1 -2
  109. data/test/bridges/paperclip_test.rb +5 -5
  110. data/test/class_with_finder.rb +2 -2
  111. data/test/company.rb +2 -2
  112. data/test/config/create_test.rb +4 -2
  113. data/test/config/nested_test.rb +1 -1
  114. data/test/config/show_test.rb +1 -1
  115. data/test/config/update_test.rb +7 -6
  116. data/test/data_structures/action_links_test.rb +1 -1
  117. data/test/data_structures/sorting_test.rb +7 -0
  118. data/test/misc/active_record_permissions_test.rb +1 -9
  119. data/test/misc/attribute_params_test.rb +8 -8
  120. data/test/misc/calculation_test.rb +1 -1
  121. data/test/misc/constraints_test.rb +2 -2
  122. data/test/misc/convert_numbers_format_test.rb +3 -3
  123. data/test/misc/lang_test.rb +1 -1
  124. data/test/misc/parse_datetime_test.rb +3 -4
  125. data/test/misc/tableless_test.rb +6 -0
  126. data/test/mock_app/Rakefile +1 -1
  127. data/test/mock_app/config/application.rb +1 -1
  128. data/test/mock_app/config/boot.rb +1 -1
  129. data/test/mock_app/config/environment.rb +2 -2
  130. data/test/test_helper.rb +8 -1
  131. metadata +38 -13
@@ -1,5 +1,5 @@
1
1
  try {
2
- <% form_selector ||= "#{element_form_id(:action => :update, :id => @record.try(:id) || params[:id])}" %>
2
+ <% form_selector ||= "#{element_form_id(:action => :update, :id => @record&.id || params[:id])}" %>
3
3
  var action_link = ActiveScaffold.find_action_link('<%= form_selector %>');
4
4
  if (action_link) action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'messages')) %>');
5
5
  <% if successful? %>
@@ -1,2 +1,2 @@
1
- ActiveScaffold.update_row('<%= element_row_id(:action => :list, :id => @record.try(:id)) %>', '<%= escape_javascript render('list_record', :record => @record) %>');
1
+ ActiveScaffold.update_row('<%= element_row_id(action: :list, id: @record&.id) %>', '<%= escape_javascript render('list_record', record: @record) %>');
2
2
  <%= render :partial => 'update_calculations', :formats => [:js] %>
@@ -15,7 +15,7 @@
15
15
  ActiveScaffold.update_inplace_edit('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>', <%= column_empty?(formatted_value).to_json %>);
16
16
  <% if ipe_update == :columns && @column.update_columns && !@column.update_columns.empty?
17
17
  @rendered = Set.new([@column.name]) -%>
18
- <%= render :partial => 'update_column', :collection => @column.update_columns & active_scaffold_config.list.columns.names, :locals => {:row_id => element_row_id(:action => :list, :id => @record.id)} %>
18
+ <%= render :partial => 'update_column', :collection => @column.update_columns & active_scaffold_config.list.columns.visible_columns_names, :locals => {:row_id => element_row_id(:action => :list, :id => @record.id)} %>
19
19
  <% end %>
20
20
  <% end -%>
21
21
  <% else -%>
@@ -9,6 +9,7 @@ module ActiveScaffold
9
9
  autoload :Finder, 'active_scaffold/finder'
10
10
  autoload :MarkedModel, 'active_scaffold/marked_model'
11
11
  autoload :OrmChecks, 'active_scaffold/orm_checks'
12
+ autoload :Registry, 'active_scaffold/registry'
12
13
  autoload :RespondsToParent, 'active_scaffold/responds_to_parent'
13
14
  autoload :Tableless, 'active_scaffold/tableless'
14
15
  autoload :Version, 'active_scaffold/version'
@@ -44,16 +45,18 @@ module ActiveScaffold
44
45
  class ActionNotAllowed < SecurityError; end
45
46
  class ReverseAssociationRequired < RuntimeError; end
46
47
 
47
- mattr_accessor :delayed_setup
48
- mattr_accessor :stylesheets
48
+ mattr_accessor :delayed_setup, instance_writer: false
49
+ mattr_accessor :stylesheets, instance_writer: false
49
50
  self.stylesheets = []
50
- mattr_accessor :javascripts
51
+ mattr_accessor :javascripts, instance_writer: false
51
52
  self.javascripts = []
52
53
 
53
- def self.js_framework=(framework)
54
- @@js_framework = framework
54
+ mattr_reader :threadsafe
55
+ def self.threadsafe!
56
+ @@threadsafe = true
55
57
  end
56
58
 
59
+ mattr_writer :js_framework, instance_writer: false
57
60
  def self.js_framework
58
61
  @@js_framework ||=
59
62
  if defined? Jquery
@@ -63,10 +66,7 @@ module ActiveScaffold
63
66
  end
64
67
  end
65
68
 
66
- def self.js_config=(config)
67
- @@js_config = config
68
- end
69
-
69
+ mattr_writer :js_config, instance_writer: false
70
70
  def self.js_config
71
71
  @@js_config ||= {:scroll_on_close => :checkInViewport}
72
72
  end
@@ -75,10 +75,7 @@ module ActiveScaffold
75
75
  # name of bridge subdir should be used to exclude it
76
76
  # eg
77
77
  # ActiveScaffold.exclude_bridges = [:cancan, :ancestry]
78
- def self.exclude_bridges=(bridges)
79
- @@exclude_bridges = bridges
80
- end
81
-
78
+ mattr_writer :exclude_bridges, instance_writer: false
82
79
  def self.exclude_bridges
83
80
  @@exclude_bridges ||= []
84
81
  end
@@ -94,5 +91,6 @@ end
94
91
  require 'active_scaffold/engine'
95
92
  require 'ice_nine'
96
93
  require 'ice_nine/core_ext/object'
94
+ require 'request_store'
97
95
  # TODO: clean up extensions. some could be organized for autoloading, and others could be removed entirely.
98
96
  Dir["#{File.dirname __FILE__}/active_scaffold/extensions/*.rb"].each { |file| require file }
@@ -3,13 +3,13 @@ module ActiveScaffold::Actions
3
3
  def self.included(base)
4
4
  base.class_eval do
5
5
  before_action :set_vary_accept_header
6
- before_action :handle_user_settings
7
6
  before_action :check_input_device
8
7
  before_action :register_constraints_with_action_columns, :unless => :nested?
9
8
  after_action :clear_flashes
10
9
  after_action :clear_storage
11
10
  rescue_from ActiveScaffold::RecordNotAllowed, ActiveScaffold::ActionNotAllowed, :with => :deny_access
12
11
  end
12
+ base.helper_method :active_scaffold_config
13
13
  base.helper_method :successful?
14
14
  base.helper_method :nested?
15
15
  base.helper_method :grouped_search?
@@ -104,7 +104,7 @@ module ActiveScaffold::Actions
104
104
  end
105
105
 
106
106
  def subform_child_association
107
- params[:child_association].presence || (@scope.split(']').first.sub(/^\[/, '').presence if @scope)
107
+ params[:child_association].presence || @scope&.split(']')&.first&.sub(/^\[/, '').presence
108
108
  end
109
109
 
110
110
  def parent_controller_name
@@ -113,7 +113,7 @@ module ActiveScaffold::Actions
113
113
 
114
114
  def set_parent(record)
115
115
  cfg = main_form_controller.active_scaffold_config
116
- association = cfg.columns[subform_child_association].try(:association).try(:reverse_association)
116
+ association = cfg.columns[subform_child_association]&.association&.reverse_association
117
117
  return if association.nil?
118
118
 
119
119
  parent_model = cfg.model
@@ -248,8 +248,10 @@ module ActiveScaffold::Actions
248
248
  conditions[key] =
249
249
  if value.is_a?(Array)
250
250
  value.map { |v| v == '' && not_string ? nil : ActiveScaffold::Core.column_type_cast(v, column) }
251
+ elsif value == '' && (not_string || column.null)
252
+ ActiveScaffold::Core.column_type_cast(column.default, column)
251
253
  else
252
- value == '' && not_string ? nil : ActiveScaffold::Core.column_type_cast(value, column)
254
+ ActiveScaffold::Core.column_type_cast(value, column)
253
255
  end
254
256
  conditions[key] = Range.new(*conditions[key]) if range
255
257
  end
@@ -258,11 +260,16 @@ module ActiveScaffold::Actions
258
260
  end
259
261
 
260
262
  def new_model
263
+ # ignore nested unrelated to current controller, e.g. adding record in subform inside subform, would create wrong parent_record
264
+ if nested? && nested.association && nested.association.klass != active_scaffold_config.model
265
+ return active_scaffold_config.model.new
266
+ end
261
267
  relation = beginning_of_chain
262
268
  config = active_scaffold_config_for(relation.klass) if nested? && nested.plural_association?
263
- if config && config._columns_hash[column = relation.klass.inheritance_column]
269
+ column = relation.klass.inheritance_column if config
270
+ if column && config._columns_hash[column]
264
271
  model_name = params.delete(column) # in new action inheritance_column must be in params
265
- model_name ||= params[:record].delete(column) if params[:record].present? # in create action must be inside record key
272
+ model_name ||= params[:record]&.delete(column) # in create action must be inside record key
266
273
  model_name = model_name.camelize if model_name
267
274
  model_name ||= active_scaffold_config.model.name
268
275
  build_options = {column.to_sym => model_name} if model_name
@@ -276,17 +283,6 @@ module ActiveScaffold::Actions
276
283
  @record = find_if_allowed(params[:id], crud_type_or_security_options, klass)
277
284
  end
278
285
 
279
- def active_scaffold_session_storage_key(id = nil)
280
- id ||= params[:eid] || "#{params[:controller]}#{"_#{nested_parent_id}" if nested?}"
281
- "as:#{id}"
282
- end
283
-
284
- def active_scaffold_session_storage(id = nil)
285
- session_index = active_scaffold_session_storage_key(id)
286
- session[session_index] ||= {}
287
- session[session_index]
288
- end
289
-
290
286
  def active_scaffold_embedded_params
291
287
  params[:embedded] || {}
292
288
  end
@@ -300,19 +296,9 @@ module ActiveScaffold::Actions
300
296
  response.headers['Vary'] = 'Accept'
301
297
  end
302
298
 
303
- # at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.
304
- def handle_user_settings
305
- storage = active_scaffold_config.store_user_settings ? active_scaffold_session_storage : {}
306
- active_scaffold_config.actions.each do |action_name|
307
- conf_instance = active_scaffold_config.send(action_name) rescue next
308
- next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it
309
- conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, storage, params)
310
- end
311
- end
312
-
313
299
  def check_input_device
314
300
  if session[:input_device_type].nil?
315
- if request.env['HTTP_USER_AGENT'] && request.env['HTTP_USER_AGENT'][/(iPhone|iPod|iPad)/i]
301
+ if request.env['HTTP_USER_AGENT'] =~ /(iPhone|iPod|iPad)/i
316
302
  session[:input_device_type] = 'TOUCH'
317
303
  session[:hover_supported] = false
318
304
  else
@@ -340,7 +326,7 @@ module ActiveScaffold::Actions
340
326
 
341
327
  def params_hash(value)
342
328
  if controller_params?(value)
343
- Rails.version < '4.2' ? value.clone.permit! : value.to_unsafe_h.with_indifferent_access
329
+ value.to_unsafe_h.with_indifferent_access
344
330
  else
345
331
  value
346
332
  end
@@ -361,7 +347,7 @@ module ActiveScaffold::Actions
361
347
  else
362
348
  @action_link = active_scaffold_config.action_links[action_name]
363
349
  if params[:id]
364
- crud_type_or_security_options ||= {:crud_type => (request.post? || request.put?) ? :update : :delete, :action => action_name}
350
+ crud_type_or_security_options ||= {:crud_type => request.post? || request.put? ? :update : :delete, :action => action_name}
365
351
  get_row(crud_type_or_security_options)
366
352
  if @record.nil?
367
353
  self.successful = false
@@ -382,11 +368,15 @@ module ActiveScaffold::Actions
382
368
  end
383
369
 
384
370
  def action_update_respond_to_html
385
- redirect_to :action => 'index'
371
+ if params[:iframe] == 'true' # was this an iframe post ?
372
+ responds_to_parent { action_update_respond_to_js }
373
+ else
374
+ redirect_to :action => 'index'
375
+ end
386
376
  end
387
377
 
388
378
  def action_update_respond_to_js
389
- render(:action => 'on_action_update')
379
+ render :action => 'on_action_update', :formats => [:js], :layout => false
390
380
  end
391
381
 
392
382
  def action_update_respond_to_xml
@@ -420,11 +410,11 @@ module ActiveScaffold::Actions
420
410
  end
421
411
 
422
412
  def virtual_columns(columns)
423
- columns.reject { |col| active_scaffold_config.model.columns_hash[col.to_s] || active_scaffold_config.columns[col].try(:association) }
413
+ columns.reject { |col| active_scaffold_config.model.columns_hash[col.to_s] || active_scaffold_config.columns[col]&.association }
424
414
  end
425
415
 
426
416
  def association_columns(columns)
427
- columns.select { |col| active_scaffold_config.columns[col].try(:association) }
417
+ columns.select { |col| active_scaffold_config.columns[col]&.association }
428
418
  end
429
419
 
430
420
  private
@@ -457,7 +447,7 @@ module ActiveScaffold::Actions
457
447
  klass = klass.superclass
458
448
  controller = self.class.active_scaffold_controller_for(klass)
459
449
  cfg = controller.active_scaffold_config if controller.uses_active_scaffold?
460
- next unless cfg && cfg.add_sti_create_links?
450
+ next unless cfg&.add_sti_create_links?
461
451
  return controller if cfg.sti_children.map(&:to_s).include? self.class.active_scaffold_config.model.name.underscore
462
452
  end
463
453
  rescue ActiveScaffold::ControllerNotFound => ex
@@ -76,7 +76,7 @@ module ActiveScaffold::Actions
76
76
  end
77
77
 
78
78
  def create_columns_names
79
- active_scaffold_config.create.columns.names
79
+ active_scaffold_config.create.columns.visible_columns_names
80
80
  end
81
81
 
82
82
  # A simple method to find and prepare an example new record for the form
@@ -24,11 +24,11 @@ module ActiveScaffold::Actions
24
24
  end
25
25
 
26
26
  def destroy_respond_to_xml
27
- render :xml => successful? ? '' : response_object, :only => active_scaffold_config.list.columns.names, :status => response_status
27
+ render :xml => successful? ? '' : response_object, :only => active_scaffold_config.list.columns.visible_columns_names, :status => response_status
28
28
  end
29
29
 
30
30
  def destroy_respond_to_json
31
- render :json => successful? ? '' : response_object, :only => active_scaffold_config.list.columns.names, :status => response_status
31
+ render :json => successful? ? '' : response_object, :only => active_scaffold_config.list.columns.visible_columns_names, :status => response_status
32
32
  end
33
33
 
34
34
  def destroy_find_record
@@ -56,10 +56,10 @@ module ActiveScaffold::Actions
56
56
 
57
57
  def custom_finder_options
58
58
  if grouped_search?
59
- group_sql = calculation_for_group_by(search_group_column.try(:field) || search_group_name)
59
+ group_sql = calculation_for_group_by(search_group_column&.field || search_group_name)
60
60
  group_by = group_sql.respond_to?(:to_sql) ? group_sql.to_sql : group_sql
61
61
 
62
- select_query = quoted_select_columns(search_group_column.try(:select_columns))
62
+ select_query = quoted_select_columns(search_group_column&.select_columns)
63
63
  select_query << group_sql.as(search_group_column.name.to_s) if search_group_column && group_sql.respond_to?(:to_sql)
64
64
  if active_scaffold_config.model.columns_hash.include?(active_scaffold_config.model.inheritance_column)
65
65
  select_query << active_scaffold_config.columns[active_scaffold_config.model.inheritance_column].field
@@ -71,7 +71,7 @@ module ActiveScaffold::Actions
71
71
  if respond_to?(:"#{action}_columns", true)
72
72
  send(:"#{action}_columns")
73
73
  else
74
- active_scaffold_config.send(action).columns.collect_visible(:flatten => true)
74
+ active_scaffold_config.send(action).columns.visible_columns(flatten: true)
75
75
  end
76
76
  joins_cols, preload_cols = columns.select { |c| c.includes.present? }.partition do |col|
77
77
  includes_need_join?(col, sorting) && !grouped_search?
@@ -82,7 +82,7 @@ module ActiveScaffold::Actions
82
82
  end
83
83
 
84
84
  def set_includes_for_sorting(columns, sorting)
85
- sorting.each do |col, _|
85
+ sorting.each_key do |col|
86
86
  next unless col.includes.present? && !columns.include?(col)
87
87
  if active_scaffold_config.model.connection.needs_order_expressions_in_select?
88
88
  active_scaffold_references << col.includes
@@ -97,8 +97,8 @@ module ActiveScaffold::Actions
97
97
  end
98
98
 
99
99
  def scoped_habtm?(column)
100
- assoc = column.association if column.association.try :collection?
101
- assoc && assoc.habtm? && assoc.scope
100
+ assoc = column.association if column.association&.collection?
101
+ assoc&.habtm? && assoc.scope
102
102
  end
103
103
 
104
104
  def get_row(crud_type_or_security_options = :read)
@@ -132,11 +132,12 @@ module ActiveScaffold::Actions
132
132
  page = page.pager.last
133
133
  active_scaffold_config.list.user.page = page.number
134
134
  end
135
- @page, @records = page, page.items
135
+ @page = page
136
+ @records = page.items
136
137
  end
137
138
 
138
139
  def quoted_select_columns(columns)
139
- columns.map { |c| active_scaffold_config.columns[c].try(:field) || c } if columns
140
+ columns&.map { |c| active_scaffold_config.columns[c]&.field || c }
140
141
  end
141
142
 
142
143
  def do_refresh_list
@@ -216,7 +217,7 @@ module ActiveScaffold::Actions
216
217
  end
217
218
 
218
219
  def list_columns
219
- @list_columns ||= active_scaffold_config.list.columns.collect_visible
220
+ @list_columns ||= active_scaffold_config.list.columns.visible_columns
220
221
  end
221
222
 
222
223
  def list_columns_names
@@ -27,12 +27,12 @@ module ActiveScaffold::Actions
27
27
  def set_nested
28
28
  @nested = nil
29
29
  return unless params[:parent_scaffold] && (params[:association] || params[:named_scope])
30
- @nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, params)
31
- register_constraints_with_action_columns(@nested.constrained_fields) unless @nested.nil?
30
+ @nested = ActiveScaffold::DataStructures::NestedInfo.get(self.class.active_scaffold_config.model, params)
32
31
  end
33
32
 
34
33
  def configure_nested
35
34
  return unless nested?
35
+ register_constraints_with_action_columns(nested.constrained_fields)
36
36
  active_scaffold_config.list.user.label = nested_label
37
37
  unless active_scaffold_config.nested.ignore_order_from_association
38
38
  chain = beginning_of_chain
@@ -84,13 +84,13 @@ module ActiveScaffold::Actions
84
84
  if nested.association.collection?
85
85
  nested_parent_record.send(nested.association.name)
86
86
  elsif nested.association.through? # has_one :through
87
- active_scaffold_config.model.where(active_scaffold_config.model.primary_key => nested_parent_record.send(nested.association.name).try(:id))
87
+ active_scaffold_config.model.where(active_scaffold_config.model.primary_key => nested_parent_record.send(nested.association.name)&.id)
88
88
  elsif nested.association.has_one?
89
- active_scaffold_config.model.where(nested.child_association.foreign_key => nested_parent_record.send(nested.association.association_primary_key))
89
+ active_scaffold_config.model.where(nested.child_association.name => nested_parent_record)
90
90
  elsif nested.association.belongs_to?
91
91
  nested_belongs_to_chain
92
92
  else # never should get here
93
- active_scaffold_config.model
93
+ raise 'missing condition for nested beginning_of_chain'
94
94
  end
95
95
  elsif nested? && nested.scope
96
96
  nested_parent_record.send(nested.scope)
@@ -181,11 +181,11 @@ module ActiveScaffold::Actions::Nested
181
181
  end
182
182
 
183
183
  def add_existing_respond_to_xml
184
- render :xml => response_object, :only => active_scaffold_config.list.columns.names, :status => response_status
184
+ render :xml => response_object, :only => active_scaffold_config.list.columns.visible_columns_names, :status => response_status
185
185
  end
186
186
 
187
187
  def add_existing_respond_to_json
188
- render :json => response_object, :only => active_scaffold_config.list.columns.names, :status => response_status
188
+ render :json => response_object, :only => active_scaffold_config.list.columns.visible_columns_names, :status => response_status
189
189
  end
190
190
 
191
191
  def destroy_existing_respond_to_html
@@ -198,11 +198,11 @@ module ActiveScaffold::Actions::Nested
198
198
  end
199
199
 
200
200
  def destroy_existing_respond_to_xml
201
- render :xml => successful? ? '' : response_object, :only => active_scaffold_config.list.columns.names, :status => response_status
201
+ render :xml => successful? ? '' : response_object, :only => active_scaffold_config.list.columns.visible_columns_names, :status => response_status
202
202
  end
203
203
 
204
204
  def destroy_existing_respond_to_json
205
- render :json => successful? ? '' : response_object, :only => active_scaffold_config.list.columns.names, :status => response_status
205
+ render :json => successful? ? '' : response_object, :only => active_scaffold_config.list.columns.visible_columns_names, :status => response_status
206
206
  end
207
207
 
208
208
  def add_existing_authorized?(record = nil)
@@ -19,7 +19,7 @@ module ActiveScaffold::Actions
19
19
  def do_search
20
20
  if search_params.is_a?(String) && search_params.present?
21
21
  query = search_params.to_s.strip
22
- columns = active_scaffold_config.search.columns
22
+ columns = active_scaffold_config.search.columns.visible_columns
23
23
  text_search = active_scaffold_config.search.text_search
24
24
  query = query.split(active_scaffold_config.search.split_terms) if active_scaffold_config.search.split_terms
25
25
  search_conditions = self.class.conditions_for_columns(query, columns, text_search)
@@ -35,7 +35,7 @@ module ActiveScaffold::Actions
35
35
  end
36
36
 
37
37
  def show_columns_names
38
- active_scaffold_config.show.columns.names
38
+ active_scaffold_config.show.columns.visible_columns_names
39
39
  end
40
40
 
41
41
  # A simple method to retrieve and prepare a record for showing.
@@ -2,7 +2,9 @@ module ActiveScaffold::Actions
2
2
  module Subform
3
3
  def edit_associated
4
4
  do_edit_associated
5
- render :action => 'edit_associated', :formats => [:js], :readonly => @column.association.readonly?
5
+ respond_to do |format|
6
+ format.js { render :action => 'edit_associated', :formats => [:js], :readonly => @column.association.readonly? }
7
+ end
6
8
  end
7
9
 
8
10
  protected
@@ -65,7 +65,8 @@ module ActiveScaffold::Actions
65
65
  else
66
66
  @updated_record = @record
67
67
  # get_row so associations are cached like in list action
68
- @record = get_row rescue nil # if record doesn't fullfil current conditions remove it from list
68
+ # if record doesn't fullfil current conditions remove it from list
69
+ @record = get_row rescue nil # rubocop:disable Style/RescueModifier
69
70
  end
70
71
  end
71
72
  flash.now[:info] = as_(:updated_model, :model => ERB::Util.h((@updated_record || @record).to_label)) if active_scaffold_config.update.persistent
@@ -82,7 +83,7 @@ module ActiveScaffold::Actions
82
83
  end
83
84
 
84
85
  def update_columns_names
85
- active_scaffold_config.update.columns.names
86
+ active_scaffold_config.update.columns.visible_columns_names
86
87
  end
87
88
 
88
89
  # A simple method to find and prepare a record for editing
@@ -150,12 +151,12 @@ module ActiveScaffold::Actions
150
151
  value ||=
151
152
  unless @column.column.nil? || @column.column.null
152
153
  default_val = @column.column.default
153
- default_val = ActiveScaffold::Core.column_type_cast default_val, @column.column if Rails.version >= '4.2.0'
154
+ default_val = ActiveScaffold::Core.column_type_cast default_val, @column.column
154
155
  default_val == true ? false : default_val
155
156
  end
156
157
  unless @column.nil?
157
158
  value = column_value_from_param_value(value_record, @column, value)
158
- value = [] if value.nil? && @column.form_ui && @column.association.try(:collection?)
159
+ value = [] if value.nil? && @column.form_ui && @column.association&.collection?
159
160
  end
160
161
 
161
162
  value_record.send("#{@column.name}=", value)