class ViewComponent
include ActiveModel::Model
attr_accessor :context
def render
context.render(
partial: "components/#{template_path}",
locals: { component: self }
)
end
private
def template_path
self.class.to_s.underscore
end
end
Slide 14
Slide 14 text
# object at app/view_components/comment_box.rb
# template at app/views/components/_comment_box.html.erb
class CommentBox < ViewComponent
end
class CommentThread < ViewComponent
end
class CommentForm < ViewComponent
end