Ben Koshy

Joined

390 Experience
3 Lessons Completed
0 Questions Solved

Activity

Posted in Thousand separator and Number formating

What about using the rails attirbutes API for this problem: https://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html? As of 2022-10-03 - there is a money example there (just search for: "Creating Custom Types").

Is it any different from submitting a form with a date input, and then magically getting a date time object back when using an active record object?

post_params(:created_at)  # => some string
post.created_at # => DateTime object

Money example:

car.price = "$ 100,000,000" # a string
car.price # => 10e8 # wow: we get it turned into a number, automatically!

Posted in Docker Basics for Rails Discussion

Sweet thanks for the tutorial.

Does anyone know how to deploy AN UPDATE to your rails app: for example, I've made some bug fixes.

I want to deploy these change to an already running docker container hosted on a Digital Ocean droplet.

Any ideas?

Would anyone know how to do this for esbuild?

Posted in Vue.js Components in Rails Views Discussion

This looks like Rails UJS born-again: add in a simple html attribute and BOOM: you get all this functionality for free with minimal effort. I would also add that if this approach is combined with a stimulus controller: and you can load and initialize vue components via AJAX, or turbo_frames, or even turbo streams. best bit.

Posted in Hotwire Modal Forms Discussion

yeah easily possible, i've managed to implement a hello world in this.

the trick is to have the new_room (or new chat/tweet or whatever your model is) OUTSIDE the modal form, so that when it is cancelled, you can still access a completely new form by hitting that button again.

the form is fetching using the turbo frame, and you simply use a stimulus controller to initialize it, and you can when you disconnect the controller simply hide it. It's simple enough and works like a....something that works really well.

Chris' code did not work for me.

This is what worked for me, given I am using webpacker:

/// app/javascript/packs/application.js
// add this line:
require("../trix_attachments.js")

// now we have to add the above javascript file in
// I have included it outside the packs folder
// if you want to change the location, be sure to also change the path:

// Listen for the Trix attachment event to trigger upload
document.addEventListener("trix-attachment-add", function(event) {
  var attachment = event.attachment;
  if (attachment.file) {
    return uploadAttachment(attachment);
  }
});

function uploadAttachment(attachment) {

  // Create our form data to submit
  var file = attachment.file;
  var form = new FormData;
  form.append("Content-Type", file.type);
  form.append("document[file]", file); // change to suit your circumstances!!

  // Create our XHR request
  var xhr = new XMLHttpRequest;
  xhr.open("POST", "/documents.json", true);

    // I am posting to the doucments route - your situation may be different!

  var csrfToken = $('meta[name="csrf-token"]').attr('content');
  xhr.setRequestHeader("X-CSRF-Token", csrfToken);  

  // Report file uploads back to Trix
  xhr.upload.onprogress = function(event) {
    var progress = event.loaded / event.total * 100;
    attachment.setUploadProgress(progress);
  }

  // Tell Trix what url and href to use on successful upload
  xhr.onload = function() {
    if (xhr.status === 201) {
      var data = JSON.parse(xhr.responseText);
      return attachment.setAttributes({
        url: data.image_url,
        href: data.url
      })
    }
  }

  return xhr.send(form);
}

Enjoy! And I hope that helps.

Posted in In-App Messages Between Users Discussion

Would you know if one can make Mailboxer work with Action text?

Posted in Multitenancy with the Apartment gem Discussion

Nice find! Thanks for pointing it out. It's probably enough to sway me against using apartment.

Posted in Multitenancy with the Apartment gem Discussion

Hi all

WARNING RE: Multiple schemas

For those implementing a multiple schema approach - where each customer / client / project etc. has their own schema, it is not without its problems. Consider this warning here - if you plan on using Heroku: https://devcenter.heroku.com/articles/heroku-postgresql#multiple-schemas . Granted, this is a problem that you will likely WANT to have (i.e. this means that your SAAS will have taken off into the stratosphere, if you have 50+ or more customer accounts), but it is a warning that is worth giving some pause for consideration.

Memory Bloat, Migration Problems
Tenancy by schema might be very good and quick for a small number of clients, but it seems like once you start scaling, you may run into troubles. Brad Robertson suggests are saying you may run into client memory bloat (because active record caches all tables in all schemas), so you'd get 500 mb memory bloat right off the bat. Robertson also cites anecdotal opinions that it's costing a lot more to house a database using the schema approach.

Source: https://influitive.io/our-multi-tenancy-journey-with-postgres-schemas-and-apartment-6ecda151a21f

This is something that I have not looked at, at details - i don't have concrete numbers, or reasons: wondering if anyone has any thoughts on this?

(btw Chris -- thank you for your generous tutorials / time.)