David Kimura PRO
Joined 7/18/2015
Drifting Ruby Owner
David Kimura PRO said over 4 years ago on Deployment alternatives :
I do agree that it is a layer of additional complexity. However, there are some side benefits for containerization in a production environment. I do agree that it may be overkill, but it can also be nice.

I haven't tested current performance implications, but when Docker was LXC, there was about a 2% performance overhead due to the containerization.

I think that using docker for production use has two main benefits; compilation of the project and auto scaling.

Since we can provide a complete package (the docker image) to the hosting environment, we don't have to wait 2-6 minutes for the deployment to take place. The deployment process should just pull the image and run a container. This kind of plays into the auto scaling. Typically when an autoscaling infrastructure, a new VM would need to be provisioned, set up and the application deployed. This could take 15 minutes or so and the traffic spike could be over by the time the machine is ready. A docker container upscale could be live in under a minute.

David Kimura PRO said over 4 years ago on esbuild for Rails :
That's the approach I take with esbuild and cssbundling. You can check out https://www.github.com/driftingruby/template for what I use with new episodes. This uses jsbundling and cssbundling and installs bootstrap.

David Kimura PRO said over 4 years ago on Cropping Active Storage Uploads :
I did make an update to the show notes on how I got this working for a Rails 7.0.1 application with the token and attachment name.

David Kimura PRO said over 4 years ago on Cropping Active Storage Uploads :
You might be able to capture some of the functionality with editing an existing image with something like this. You need to let the stimulus controller know that there is an existing image, so on the cropper controller, an additional value was added "existing". We set this value in the view where we are initializing the stimulus controller.  However, it does seem a bit buggy, but this should hopefully help you move forward with this feature.

--- a/app/javascript/controllers/cropper_controller.js
+++ b/app/javascript/controllers/cropper_controller.js
@@ -4,11 +4,20 @@ import "cropperjs/dist/cropper.css"
 
 export default class extends Controller {
   static targets = ["image"]
-  static values = { model: String }
+  static values = { model: String, existing: String }
+
+  connect() {
+    if (this.existingValue == "true") {
+      this.changed()
+    }
+  }
 
   changed() {
     let _this = this
-    new Cropper(this.imageTarget, {
+    if (this.cropper != undefined) {
+      this.cropper.destroy()
+    }
+    this.cropper = new Cropper(this.imageTarget, {
       crop(event) {
         _this.crop_x().value = event.detail.x
         _this.crop_y().value = event.detail.y
diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb
index 9e73386..c4fb40a 100644
--- a/app/views/users/_form.html.erb
+++ b/app/views/users/_form.html.erb
@@ -17,9 +17,9 @@
   <div class="field"
        data-controller='instant-upload cropper'
        data-cropper-model-value='user'
+       data-cropper-existing-value="<%= @user.avatar.attached? %>"
       data-instant-upload-token-value="<%= direct_upload_token("User#avatar") %>"
-      data-instant-upload-attachment-value='User#avatar'
-      >
+      data-instant-upload-attachment-value='User#avatar'>
     <%= form.label :avatar %>
     <%= form.file_field :avatar,
           'data-instant-upload-target': 'input',

David Kimura PRO said over 4 years ago on Hotwire Modals :
How was bootstrap installed? I created the new app with

rails new example --javascript esbuild --css bootstrap