mert

mert

AWDWR 7, page 152, page 153:

Hello everyone,

I’m a little bit lost on the hotwire part. I didn’t fully understand it.

On page 152 @rubys does the hotwire in one way. Then on page 153 he creates creatre.turbo_stream.erb and add 2 turbo_stream.replace .... I understand he is showing 2 ways of doing it. However I feel like I got confused. This is a chapter I have to read multiple times.

Can someone explain more about this sentence on page 152: “Since we followed the default
naming conventions for the template, we don’t need to pass any arguments”. I know in rails we use a lot of conventions but this went over my head.

On page 153 I got lost at this line: format.turbo_stream { @current_item = @line_item }, Where did @current_item came from, where do we really use it? We don’t use it at our 2 turbo_stream replace ...

Mert

Marked As Solved

rubys

rubys

Author of Agile Web Development With Rails

On page 152 @rubys does the hotwire in one way. Then on page 153 he creates creatre.turbo_stream.erb and add 2 turbo_stream.replace .... I understand he is showing 2 ways of doing it. However I feel like I got confused. This is a chapter I have to read multiple times.

You are correct that I am showing two different ways of constructing a response. I would welcome any suggestions as to how this could be improved.

Can someone explain more about this sentence on page 152: “Since we followed the default naming conventions for the template, we don’t need to pass any arguments”. I know in rails we use a lot of conventions but this went over my head.

What I meant by that is that we don’t need to specify any arguments to render, so in fact no calls to render are required. Compare this code with what it replaced to see what I mean:

          render turbo_stream: turbo_stream.replace(
            :cart,
            partial: 'layouts/cart',
            locals: { cart: @cart }
          )

I’ll rework this paragraph.

On page 153 I got lost at this line: format.turbo_stream { @current_item = @line_item }, Where did @current_item came from, where do we really use it? We don’t use it at our 2 turbo_stream replace ...

It will be used by the rendering of the cart, which is done here:

<%= render partial: 'layouts/cart', locals: {cart: @cart} %>

I’ll add a sentence or two to explain why we are setting this value.

Popular Prag Prog topics Top

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
dsmith42
Hey there, I’m enjoying this book and have learned a few things alredayd. However, in Chapter 4 I believe we are meant to see the “&gt;...
New
hazardco
On page 78 the following code appears: &lt;%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
kolossal
Hi, I need some help, I’m new to rust and was learning through your book. but I got stuck at the last stage of distribution. Whenever I t...
New
EdBorn
Title: Agile Web Development with Rails 7: (page 70) I am running windows 11 pro with rails 7.0.3 and ruby 3.1.2p20 (2022-04-12 revision...
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New

Other popular topics Top

PragmaticStudio
Let’s get real. As in really knowing—clearly and practically—what’s up with Phoenix LiveView. What is it? How does it work? What can I ...
New
axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
AstonJ
Or looking forward to? :nerd_face:
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
New
AstonJ
Chris Seaton, the creator of TruffleRuby has died. It appears from suicide :cry: He left this note on Twitter on the weekend: And one...
New
PragmaticBookshelf
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New