mert

mert

Agile Web Development with Rails 7: page 152, page 153:

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

johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=&gt; (create-...
New
raul
Page 28: It implements io.ReaderAt on the store type. Sorry if it’s a dumb question but was the io.ReaderAt supposed to be io.ReadAt? ...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
swlaschin
The book has the same “Problem space/Solution space” diagram on page 18 as is on page 17. The correct Problem/Solution space diagrams ar...
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
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
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
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
New
dachristenson
@mfazio23 Android Studio will not accept anything I do when trying to use the Transformations class, as described on pp. 140-141. Googl...
New

Other popular topics Top

ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
OvermindDL1
Woooooooo! This is such a huge release for it, and 2 years incoming! In short, the library is now using an updated hyper backend (not j...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New

Latest in PragProg

View all threads ❯