New Discussion

Notifications

You’re not receiving notifications from this thread.

Template Locals in Rails 7.1 Discussion

5
General

This is a great addition to Rails. It makes partials feel a lot like calling methods with required and optional arguments.

Couple of nice little Easter Eggs at the end there. Love it!

One thought I had was whether the template locals can be passed into the shorthand when called render.

ie. can
<%= render @product %> handle
<%= render @products, comment_count: 2 %> or do we need to revert back to
<%= render partial: "product", product: @product, comment_count: 2 %> or even
<%= render partial: "product", locals: { product: @product, comment_count: 2 } %>

Hard to tell when reading the docs.

Sometimes I prefer to just do the long way everywhere with partial: and locals: just so I am not getting confused by the magic.

calling render... I am no longer authorised to edit my own comment WhooP!S

That should work but let me know if it doesn't!

Sorry still can't edit comments. I click edit from the comment action menu drop down and I get redirect to https://gorails.com/dashboard with a flash 'You are not authorized to perform that action'.

Join the discussion
Create an account Log in

Learning Ruby on Rails? Join our newsletter.

We won't send you spam. Unsubscribe at any time.