Skip to content

Odd behavior when rendering components within a partial #380

Answered by joeldrapper
bschrag620 asked this question in Help
Discussion options

You must be logged in to vote

ERB works based on the return values of method calls. When you see <%=, you can think of the = as being a method that pushes things to the output buffer. In pseudo code, it’s something like this.

def =(output)
  if output.is_a?(String)
    @output_buffer << output
  end
end

In your first example, you are telling ERB to output the return value of the row rendered by ActionView (line 2).

<%= render Views::Row.new(**opts) do |row|

While that is being calculated, you tell the row to render the cells (line 4).

row.render_cell(cell, **cell_opts)

This isn’t ActionView’s render method, it’s the Phlex render method and in Phlex, render immediately outputs. You don’t need to say = render.

In the en…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by bschrag620
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #379 on November 23, 2022 10:00.