Skip to main content

Stimulus JS Twitter UI: Part 1 Discussion

General • Asked by Chris Oliver
Is the source code for this (and other) episodes available? I am having some small problems following along.

Great episode! I did find some things didn't reproduce with Rails 5.2 etc.

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

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() {
    this.characterCount = this.body.length

  get body() {
    return this.bodyTarget.value

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

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.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.