New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update layouts_and_rendering.md [ci skip] #30884
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
Actually, if I'm right here, it probably makes sense to delete the final sentence of this paragraph too. |
@@ -1266,7 +1266,7 @@ You can also pass in arbitrary local variables to any partial you are rendering | |||
|
|||
In this case, the partial will have access to a local variable `title` with the value "Products Page". | |||
|
|||
TIP: Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by `_counter`. For example, if you're rendering `@products`, within the partial you can refer to `product_counter` to tell you how many times the partial has been rendered. This does not work in conjunction with the `as: :value` option. | |||
TIP: Rails also makes a counter variable available within a partial called by the collection, named after the title of the partial followed by `_counter`. For example, if you're rendering `@products` with a partial `_product.html.erb', within the partial you can refer to `product_counter` to tell you how many times the partial has been rendered. This does not work in conjunction with the `as: :value` option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I'm finding this part confusing and long winded
if you're rendering
@products
with a partial_product.html.erb', within the partial you can refer to
product_counter` to tell you how many times the partial has been rendered
What do you think about this instead?
if you're rendering
@products
with the_product.html.erb' partial you can refer to
product_counter` to tell you how many times the partial has been rendered within the partial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Eileen,
I guess what I was trying to be clear about is that the variable product_counter
would be available within the _product.html.erb
partial, and not the enclosing view (which may or may not be another partial, right?). The way I read your version, by moving the phrase 'within the partial' from where I put it to the end of the sentence you've changed the meaning slightly so that the second 'the partial' now means means the enclosing view.
I guess this might be clear from the context, but I was trying to avoid confusion with ruby constructs that make an index available such as
array.each_with_index | value, index|
#do stuff that knows about array[ index] = value
end
where you might imagine that product_counter
was made available in the calling scope.
Of course, you wouldn't be the first person to accuse me of being long-winded ...
How about this?
For example, when rendering a collection
@products
the partial_product.html.erb
can access the variableproduct_counter
that indexes the number of times it has been rendered within the enclosing view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @robwold yea I think that's better. Can you make that change and squash your commits into one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eileencodes Done. Let me know if there's any further issues.
Proposed correction- it seems that when rendering a collection and the name of a partial and the name of of the object don't agree, it uses the title of the partial, not the name of the collection, for the counter variable.
Summary
Provide a general description of the code changes in your pull
request... were there any bugs you had fixed? If so, mention them. If
these bugs have open GitHub issues, be sure to tag them here as well,
to keep the conversation linked together.
Other Information
If there's anything else that's important and relevant to your pull
request, mention that information here. This could include
benchmarks, or other information.
If you are updating any of the CHANGELOG files or are asked to update the
CHANGELOG files by reviewers, please add the CHANGELOG entry at the top of the file.
Finally, if your pull request affects documentation or any non-code
changes, guidelines for those changes are available
here
Thanks for contributing to Rails!