Save 36% for Black Friday! Learn more

Ben Koshy


40 Experience
0 Lessons Completed
0 Questions Solved


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:

// 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;"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 / * 100;

  // 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: . 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.


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.)

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.