0
0
Ruby on Railsframework~10 mins

Stimulus and Turbo (Hotwire) in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to connect a Stimulus controller named "hello" to an HTML element.

Ruby on Rails
<div data-controller="[1]">
  Hello, Stimulus!
</div>
Drag options to blanks, or click blank then click option'
Ahello
Bturbo
Capplication
Dconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong controller name in the data-controller attribute.
Forgetting to add the data-controller attribute.
2fill in blank
medium

Complete the code to make a Turbo Frame with the ID "messages".

Ruby on Rails
<turbo-frame id="[1]">
  Loading messages...
</turbo-frame>
Drag options to blanks, or click blank then click option'
Achat
Bmessages
Cnotifications
Dcomments
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect or mismatched ID for the turbo-frame.
Omitting the ID attribute.
3fill in blank
hard

Fix the error in the Stimulus controller method to log "Hello, Stimulus!" when connected.

Ruby on Rails
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  connect() {
    console.[1]("Hello, Stimulus!")
  }
}
Drag options to blanks, or click blank then click option'
Alog
Bprint
Cwrite
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.print or other incorrect console methods.
Forgetting parentheses after the method name.
4fill in blank
hard

Fill both blanks to create a Stimulus action that calls the "submit" method on form submission.

Ruby on Rails
<form data-controller="form" data-action="[1]->[2]">
  <input type="text" name="name">
  <button type="submit">Send</button>
</form>
Drag options to blanks, or click blank then click option'
Asubmit
Bform
Cclick
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping event and controller in the data-action attribute.
Using incorrect event names like 'click' for form submission.
5fill in blank
hard

Fill all three blanks to create a Turbo Stream template that replaces the element with ID "notification" with new content.

Ruby on Rails
<turbo-stream action="[1]" target="[2]">
  <template>
    <div>[3]</div>
  </template>
</turbo-stream>
Drag options to blanks, or click blank then click option'
Aappend
Bnotification
CNew notification received!
Dreplace
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong action like 'append' when intending to replace.
Mismatching the target ID with the actual element ID.