Ask A Question

Notifications

You’re not receiving notifications from this thread.

Stimulus JS Twitter UI: Part 1 Discussion

Is the source code for this (and other) episodes available? I am having some small problems following along.
Reply
Great episode! I did find some things didn't reproduce with Rails 5.2 etc.
Reply

Still pretty new to rails. What would happen during create if the @tweet.save failed validation? Trying to understand how you'd use create.js.erb to display the form with errors in create if it fails?

Reply

Great video Chris.

From Stimulus' docs, I found that we can refactor the controller class using javascript getter and setter methods, like so:

import { Controller } from "stimulus"

export default class extends Controller {
  static targets = [ "body", "characterCount" ]

  initialize() {
    this.characterCount = this.body.length
  }

  update() {
    console.log(`updating...${this.body.length}`)
    this.characterCount = this.body.length
  }

  get body() {
    return this.bodyTarget.value
  }

  set characterCount(value) {
    this.characterCountTarget.textContent = value
  }
}
Reply

I am having an issue deploying a site with stimulus via capistrano. I get the error:

ModuleNotFoundError: Module not found: Error: Can't resolve './controllers' in '/home/deploy/site/releases/20190501124321/app/javascript/packs'

My directory is:

App/javascript/packs/controllers. Inside packs I have application.js which references ./controllers.

Any ideas why this is failing?

UPDATE: I figured it out. My controllers folder didn't have anything in it yet and was not syncing.

Reply

Hi Chris,

great video!

One thing I like to do these days is, instead of responding with a create.js.erb, catch the ajax:success event in the stimulus controller (possibly even by attaching it to document: https://stimulusjs.org/reference/actions#global-events).

You don't get inline rendering of your Rails ivar this way, but you stay in the context of your controller and don't have to use that kind of "hacky" way of updating the form/character count, since you have access to this.element and your targets...

Reply

Great content Chris! I'm following but for some reason have been having problems to get the video to play. It's freezing right after I click the "Play" button

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.