Skip to content

Commit

Permalink
fixup! tabulatr_for Array of relations
Browse files Browse the repository at this point in the history
  • Loading branch information
mlt committed May 14, 2018
1 parent e0d7105 commit 459e44d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/tabulatr/rails/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ class ActionController::Base
end

def tabulatr_for(relation, tabulatr_data_class: nil, serializer: nil, render_action: nil, default_order: nil, locals: {}, &block)
table_id = params[:table_id]
if table_id and relation.is_a?(Array)
controller_path = self.class.name.underscore.gsub('/', '-')
idx = relation.index do |r|
table_id.start_with? "#{Tabulatr::Utility.formatted_name(r.name)}_table_#{controller_path}_#{self.action_name}_"
if relation.is_a?(Array)
table_id = params[:table_id]
idx = nil
if table_id
controller_path = self.class.name.underscore.gsub('/', '-')
idx = relation.index do |r|
n = "#{Tabulatr::Utility.formatted_name(r.name)}_table_#{controller_path}_#{self.action_name}_"
table_id.start_with? n
end
end
if idx
relation = relation[idx]
else
render action: render_action || action_name
return
end
relation = relation[idx]
end
klass = relation.respond_to?(:klass) ? relation.klass : relation
locals[:current_user] ||= current_user if respond_to?(:current_user)
Expand Down

0 comments on commit 459e44d

Please sign in to comment.