Chris Oliver

Joined

292,890 Experience
93 Lessons Completed
295 Questions Solved

Activity

Posted in Stripe Subscriptions: Duplicate Customers

The #card-element error comes from you trying to run this on every page regardless if the field is on the page. You'll want to add some JS to check if the element exists, and if it does not, return.

document.addEventListener("turbolinks:load", function() {
  if (!document.querySelector("#card-element")) {
      return
    }

    // rest of your code
}

As long as it helps get your app launched sooner than later! 🤓

As long as you write good scopes and before_action methods in your controllers you should be fine. I generally don't recommend doing multi-tenancy unless your data is truly separate.

Multitenant apps generally act like truly separate databases so the user data never gets shared.

Yeah, I'm not quite sure actually what benefit you get out of going with multitenancy right now. If you plan on making the Student side of things combine data from each Teacher, you're not really building a multi-tenant app. You may want to consider just building a regular Rails app and associating records to teachers like you normally would.

Yeah, so Account would have the subdomain to identify the tenant.

UserAccount

  • belongs_to :user
  • belongs_to :account

You sound like you're trying to accomplish something different though, maybe not something exactly like a normal multi-tenant app.

The question is really what are you trying to accomplish here? Are you just looking to have each teacher's data separate from other ones? If so, then just make the Teacher the tenant, and Students don't really matter. They probably would go inside the tentant because they're specific to the teacher. They would login on the Teacher's subdomain.

Posted in assign_attributes not working

Subtle one! Good catch.

Sometimes I have done virtual attributes on the User (like "user[card_"+field+"]")) and other times just directly accessing the param. It doesn't really make a difference which way you go, but the virtual attributes can make it nice to assign all the fields and then do the saving in a method on the model rather than in the controller.

Hey Muneeb,

Just create a new file in the /etc/nginx/sites-enabled directory. Name it whatever you want, just not default since that's already being used.

If you use the gem, you have to use the asset pipeline for it. This is what I would recommend anwyays. The asset pipeline is perfect for these things. Any reason why you're avoiding using the asset pipeline?

So generally you want all your account related things to be outside the tenant.

User
Account / Tenant / Organization / Team (whatever you call this)
UserAccount (join table between the two to give Users access to accounts)

Everything is goes inside the tenant since those should all be private.

Or, you can put User inside the tenant and require users to login from the correct subdomain. This is how Slack works where you can use the same email to create many accounts. They're not global so you don't have a central account.

Kinda depends on what you want to accomplish. If you want users to be signed into all their tenants at once, putting the model outside the tenant is best.

Posted in Stripe Subscriptions: Duplicate Customers

Hey Nick,

That's sure weird! I think what it looks like is happening is that your Javascript is submitting the form twice.

You can tell because the first POST to /memberships hasn't finished before the second one starts. And that's why the logs are mixed together and you have those two UPDATEs on the user. They're processing almost at exactly the same time.

You should do some debugging on your Javascript to figure out why it's executing twice and that should fix the problem.

Posted in SweetAlert integration

Hey Michael,

Not quite sure what's going on there, but any reason you're not using the gem? It already hooks into the standard rails data-confirm stuff and makes this seamless and you can customize the colors and buttons like usual.

Posted in Disaster recover plan?!

I should clarify that. If your uploads are up to S3, any thing that happens to your server won't affect those files (which is good). You can also setup your S3 to back itself up to another bucket, or another service if you wanted.

Posted in Disaster recover plan?!

Yeah, that's what I was thinking as a first version. 🙌

Posted in Disaster recover plan?!

Definitely agreed. That's on the todo list but there are a few things that are higher priority at the moment right now. Plus there are SO many configuration options for the backup gem, that it'd be hard to verify they're all correct and test them in the UI.

Posted in Disaster recover plan?!

This is a great question Karim! Exciting to get your app in production for a customer! 🍻

So a couple things to consider here:

  1. Database backups are safest when you upload them to somewhere third-party like S3. You can edit your Backup config on Hatch via SSH to use your S3 credentials for uploads. That will keep them safe in case anything happens to your server.
  2. DigitalOcean backups are handy for quick restoration of a server. You can create a new server based on your previous one in a minute or two this way. If you didn't have those, you'd need to setup a new server which takes a few minutes using Hatch. It can speed recovery up a little bit which is good.
  3. You'll want to make sure that you have practiced database restoration at least once before you go to production to be safe. Download one of the db backups from your app to your local computer and try restoring it to Postgres locally. This command should import the backup into a database: psql -U <username> -d <dbname> -1 -f <filename>.sql Once it's imported, you can check that all the same data is available locally as it was on your server.
  4. If you have file uploads that upload locally, you'll want to include those in your backup and restore process. If they're uploading to S3, you don't have to worry about it.

That's most of it. You should also setup the Backup config to notify you on slack or email for failed backups to be safe. If anything goes wrong, you'll want to address that right away.

Hey Liam!

So I use Janus for Vim. I'm guessing maybe it's a config option that comes by default then to do that if yours is different. They ship a lot of good defaults and I originally used it to just replicate my workflow from Sublime into Vim. I actually don't even know all the details of how they configure everything since it all worked out really nicely from a fresh install haha.

Maybe you can find their NERDTree config in the repo or you might like to just try out Janus itself.

Posted in Do I need rails-ujs and jquery_ujs?

I did an episode on the new Rails UJS library. It replaces everything jquery_ujs does, but it just doesn't require jQuery: https://gorails.com/episodes/rails-ujs-primer

Feel free to add jquery in, but you won't need the jquery_ujs library. Everything will still function exactly the same as before, they just want to reduce dependencies.

Very cool. Like the built-in Rails mailer previews but with a UI. http://guides.rubyonrails.o...

Since ActiveJob is just a wrapper for whatever background processor you use, all you have to do is write your code to use ActiveJob. All your emails already support ActiveJob, so to send them in the background you can just say "UserMailer.notification(user).deliver_later" and the deliver later part will create a job for it.

As for everything else like notifications and csv downloads, you'd just write your code in a job and have your controllers start the job. Nothing too fancy.

Is there anything specific I could cover for you that would help wrap your head around it?

I think most services confirm your email, but I don't know for sure if they force you to do that before using OAuth. It's definitely something to think about. Automatic merging is probably okay so long as you can trust that those accounts were already confirmed. I'm just not 100% that they are. I would guess that every service is different so it's probably safest not to auto-merge. If you find out more details on that, let us know!