What is the process of parsing representations in rails? I'm partially interested in the parsing order with raw html vs ruby ββcode in erb tags in views.
I would think that this is the order in which the view code is parsed and finally sent to the requestor:
- the controller invokes the view
- View code parsed from top to bottom
- When the rails meet the
erb tag during the parsing process: rails solves it and adds the result to the processed html (this includes erb tags that refer to helpers).
- After analyzing the whole view, the overall result is sent to the requester
This does not seem to be the case. It looks like the view code scans any erb fragments and analyzes them first (including links to helpers). After that, it will take care: rails then parses all the view code from top to bottom and sends the result to the requestor.
Take this view, for example:
# _form.html.erb <p> Hello World </p> <p> Foobar </p> <% if something_is_true %> <%= some_helper_method_that_returns_html %> <% end %>
Is this the correct order in how the rails define the views and send the result to the requester?
- Rails scans the view invoked by the controller: like any partial views referencing these links to see if there are
erb fragments- For all
erb they are allowed / converted to html and added to the html view
- Rails then parses the top-down view (which at the moment is a collection of itself plus any reference parts and all the html that was previously
erb - After the view has been fully analyzed: Rails sends the result to the request
Follow-up question : is there an order in which erb tags erb allowed? For example: is it possible that the erb tag that references helper is allowed before the erb tag that erb through the collection? Or: Rails always just resolves erb tags from top to bottom?
source share