Skip to content

How to use helpers in a component and still have previews work? #1451

Answered by unikitty37
unikitty37 asked this question in Q&A
Discussion options

You must be logged in to vote

…and, a few minutes later, inspiration strikes 🙄

Adding the following as lib/view_component_preview.rb solves the problem. Hopefully this monkey-patch doesn't break anything else, but I've not tested it fully yet…

# frozen_string_literal: true

class ViewComponent::Preview
  include Rails.application.routes.url_helpers
end

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by unikitty37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant