Skip to content
Discussion options

You must be logged in to vote

@pinzonjulian thank you for providing the detailed examples here. Some thoughts:

ViewComponent templates are compiled into instance methods on the component Ruby file. In that regard, the component and the template are the same entity. I have it on my to-do list to write up an explanation of this concept as part of the README, but here's an example:

class JobComponent
  attr_reader :job, :title, :distance_from_office

  def initialize(job: )
    @job = job
    @title = @job.title || 'Standard Job' # simple initialization
    @distance_from_office = calculate_distance_from_office # complex initialization
  end

  def calculate_distance_from_office
    # Some complex logic using something l…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@pinzonjulian
Comment options

@joelhawksley
Comment options

Answer selected by joelhawksley
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants