Method: EffectiveResourcesHelper#render_resource_buttons

Defined in:
app/helpers/effective_resources_helper.rb

#render_resource_buttons(resource, atts = {}, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/effective_resources_helper.rb', line 38

def render_resource_buttons(resource, atts = {}, &block)
  effective_resource = find_effective_resource
  actions = controller.try(:buttons) || raise('controller must be an Effective::CrudController')

  actions = if resource.kind_of?(Class)
    actions.select { |_, v| effective_resource.collection_get_actions.include?(v[:action]) }
  elsif resource.respond_to?(:persisted?) && resource.persisted?
    actions.select { |_, v| effective_resource.member_actions.include?(v[:action]) }
  else
    {}
  end

  render_resource_actions(resource, atts.merge(actions: actions), &block)
end