David Kimura PRO
Joined 7/18/2015
Drifting Ruby Owner
David Kimura PRO said over 8 years ago on Sidekiq on Production :

Thanks vad2der, that is correct if we set the REDIS_PROVIDER to the string REDISTOGO_URL instead of the environment variable.. 


David Kimura PRO said over 8 years ago on Stimulus Javascript Framework :

The easiest way to get started would be to download this file https://unpkg.com/stimulus/dist/stimulus.umd.js and add it to your vendor/assets/javascripts folder.

Then add the following into the app/assets/javascripts/application.js

//= require stimulus.umd

I then would create a folder in the app/assets/javascripts called stimulus.

Within this new folder, I create another application.js file with the contents

const appStimulus = Stimulus.Application.start()

Following the Copy to Clipboard example that they have on the docs, you would create a copy_to_clipboard_controller.js within the stimulus folder with the contents

appStimulus.register("copy_to_clipboard", class extends Stimulus.Controller {
  copy_text(e) {
    e.preventDefault()
    this.copy_address_field.select()
    document.execCommand("copy")
  }
  get copy_address_field() {
    return this.targets.find('copy_address_field')
  }
})

Take note that the constant that I created was appStimulus and within each controller, we first call appStimulus.register(...)

This should get you started with getting Stimulus up and running in an existing application without adding Webpack. I don't think that I would add the complexities of Webpack in a application just for Stimulus. This would be my preferred route in an existing application.

Also, you may find that there are problems deploying to production. You may need to update the Uglifier gem to a later version and change the line in your config/environments/production.rb

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = Uglifier.new(harmony: true)

David Kimura PRO said over 8 years ago on Stimulus Javascript Framework :

You can to some degree. Remember that you will have to have the DOM elements already existing on the page so if any of the referred JS is adding elements, there may be some disconnect with Stimulus. However, a lot of it probably can be moved over. For example, if you have a date picker which has a lot of different attributes and customization, that would probably be a good candidate. A nested forms "Add Item" & "Remove Item" links may not be a good fit since you're adding elements to the DOM.


David Kimura PRO said over 8 years ago on Continuous Integration with Travis CI :

Definitely. I use Gitlab CI/CD for my personal projects. 


David Kimura PRO said over 8 years ago on Page Specific Javascript in Ruby on Rails :

I believe that it does. Not everything needs to be a Stimulus component. Sometimes it just makes sense to have some JS sprinkles where needed. I have personally never been a huge fan of page specific javascript as it seems like there is some disconnect in the architectural planning of the application. I typically tend to write JS functions so that they can be called on later in Server Rendered Javascript responses, when launching a bootstrap modal or wherever else appropriate.