Files
grecia/app/components/admin/allowed_table_actions_component.rb
Javi Martín 1d955b7a20 Simplify using helper methods in components
The `use_helpers` method was added in ViewComponent 3.8.0, and it's
included by default in all components since version 3.11.0.

Note we sometimes delegated the `can?` method to the controller instead
of the helpers, for no particularly reason. We're unifying that code as
well.
2024-03-02 17:34:25 +01:00

21 lines
533 B
Ruby

class Admin::AllowedTableActionsComponent < ApplicationComponent
attr_reader :record, :options
use_helpers :can?
delegate :action, to: :table_actions_component
def initialize(record, **options)
@record = record
@options = options
end
private
def actions
(options[:actions] || [:edit, :destroy]).select { |action| can?(action, record) }
end
def table_actions_component
@table_actions_component ||= Admin::TableActionsComponent.new(record, **options.merge(actions: actions))
end
end