Skip to content

Instantly share code, notes, and snippets.

@bradgessler
Last active February 1, 2024 20:15
Show Gist options
  • Save bradgessler/c8385cd54b9b146a92acb77ecef80b1d to your computer and use it in GitHub Desktop.
Save bradgessler/c8385cd54b9b146a92acb77ecef80b1d to your computer and use it in GitHub Desktop.
Component helper
module ComponentHelper
def component(name, *args, **kwargs, &block)
render componentize(name).new(*args, **kwargs), &block
end
private
def componentize(name)
"#{name.to_s.classify}Component".constantize
end
end
<%= component :title, "Hello there", variant: "medium" %>
class TitleComponent < ApplicationComponent
def initialize(title, variant: "large")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment