diff options
| author | Teddy Wing | 2018-01-25 14:01:13 +0100 |
|---|---|---|
| committer | Zog | 2018-01-25 17:18:03 +0100 |
| commit | 2bf4cf2e3a9e54bc9b91bf3efcac721951df730d (patch) | |
| tree | 19c9c1c588b13b721c7d0aa61d7c9b1684f22cf4 /app/helpers | |
| parent | 9ee14d84ccfd19fb6a53c83826f352088f06b57c (diff) | |
| download | chouette-core-2bf4cf2e3a9e54bc9b91bf3efcac721951df730d.tar.bz2 | |
ComplianceControlDecorator: Convert to new action links interface
I was getting this error:
ActionView::Template::Error (undefined method `split' for nil:NilClass
Did you mean? split_all):
16:
17: / compliance controls without block
18: = render_compliance_control_block
19: = render_compliance_controls(@direct_compliance_controls)
20:
21: / compliance controls with block
22: - if params[:q] && params[:q][:compliance_control_block_id_eq_any].try(:present?)
app/helpers/table_builder_helper.rb:110:in `item_row_class_name'
app/helpers/table_builder_helper.rb:290:in `tbody'
app/helpers/table_builder_helper.rb:97:in `table_builder_2'
app/helpers/compliance_control_sets_helper.rb:79:in `block in render_table_builder'
app/helpers/compliance_control_sets_helper.rb:78:in `render_table_builder'
app/helpers/compliance_control_sets_helper.rb:71:in `block (2 levels) in render_compliance_controls'
app/helpers/compliance_control_sets_helper.rb:70:in `block in render_compliance_controls'
app/helpers/compliance_control_sets_helper.rb:69:in `render_compliance_controls'
app/views/compliance_control_sets/show.html.slim:19:in `_app_views_compliance_control_sets_show_html_slim___3528509151208629266_70279137561480'
The model name wasn't accessible from the view because this collection
is set up in an unorthodox way without a decorated collection.
Got help from Johan, and we ended up using the `model` param passed into
the table builder for this. It looks terrible with `model` all over the
place, but at least it gets us past the problem.
Refs #5586
Diffstat (limited to 'app/helpers')
| -rw-r--r-- | app/helpers/compliance_control_sets_helper.rb | 3 | ||||
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 25 |
2 files changed, 16 insertions, 12 deletions
diff --git a/app/helpers/compliance_control_sets_helper.rb b/app/helpers/compliance_control_sets_helper.rb index 57e6d9608..448d5c008 100644 --- a/app/helpers/compliance_control_sets_helper.rb +++ b/app/helpers/compliance_control_sets_helper.rb @@ -100,7 +100,8 @@ module ComplianceControlSetsHelper ], sortable: true, cls: 'table has-filter has-search', - model: ComplianceControl + model: ComplianceControl, + action: :index end metas = content_tag :div, I18n.t('compliance_control_blocks.metas.control', count: compliance_controls.count), class: 'pull-right' table + metas diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 5c9da3d36..b123da802 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -94,18 +94,21 @@ module TableBuilderHelper ) content_tag :table, thead(collection, columns, sortable, selectable, links.any?, overhead, model || collection.model, action || params[:action]) + - tbody(collection, columns, selectable, links, overhead, action || params[:action]), + tbody(collection, columns, selectable, links, overhead, model, action || params[:action]), class: cls end - def self.item_row_class_name collection - if collection.respond_to?(:model) - model_name = collection.model.name - elsif collection.respond_to?(:first) - model_name = collection.first.class.name - else - model_name = "item" - end + def self.item_row_class_name collection, model + model_name = model&.name + + model_name ||= + if collection.respond_to?(:model) + collection.model.name + elsif collection.respond_to?(:first) + collection.first.class.name + else + "item" + end model_name.split("::").last.parameterize end @@ -286,8 +289,8 @@ module TableBuilderHelper end end - def tbody(collection, columns, selectable, links, overhead, action) - model_name = TableBuilderHelper.item_row_class_name collection + def tbody(collection, columns, selectable, links, overhead, model = nil, action) + model_name = TableBuilderHelper.item_row_class_name collection, model content_tag :tbody do collection.map do |item| |
