Skip to content

using rails helpers (link_to, for instance) within a component. #1076

Answered by Spone
fakeharxy asked this question in Q&A
Discussion options

You must be logged in to vote

Here is how I would do it with slots (I removed all unrelated code for clarity). I haven't tested the code so it may need additional work :)

class StatePanel::KitReservationsStateRowComponent < ApplicationComponent
  renders_many :action_components, -> () do
    if Platform.sti_test_order_workflow.kit_reservation_scannable?(kit_reservation, user)
      BootstrapButtonComponent.new(text: translation_for(key: 'scan_kit'), href: kit_reservation_assignment_path(kit_reservation), variant: :success)
    else
      DisabledButtonComponent.new(text: translation_for(key: 'scan_kit'))
    end
  end

  # ...
end

Then in the component template:

- action_components.each do |action_component|
  = actio…

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
8 replies
@fakeharxy
Comment options

@fakeharxy
Comment options

@fakeharxy
Comment options

@Spone
Comment options

Answer selected by fakeharxy
@fakeharxy
Comment options

Comment options

You must be logged in to vote
1 reply
@reeganviljoen
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants