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

belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
leonW
I ran this command after installing the sample application: $ cards add do something --owner Brian And got a file not found error: Fil...
New
jskubick
I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
brunogirin
When I run the coverage example to report on missing lines, I get: pytest --cov=cards --report=term-missing ch7 ERROR: usage: pytest [op...
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New
dachristenson
I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1016 16827 371
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
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
PragmaticBookshelf
Author Spotlight Erin Dees @undees Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
New