Chris Oliver


234,920 Experience
17 Lessons Completed
256 Questions Solved


Posted in Import into administrate?

Imports are usually pretty unique to your app, so I imagine they intend it to be that way since your format may not exactly match the database table.

There's several episodes here on GoRails talking about importing from CSV. I'd recommend checking those out and building that out for importing with Administrate.

Nothing too fancy. users/edit comes from Devise. password/edit is a passwords controller I added.

Depends on how up-to-date you want it to be. If you're fine with every day, then write a cron job to sync and update every day or something.

If you need it to be more real-time, then trigger an API request after you load the record to sync it with the latest value. They may also provide webhooks to send you the changes as needed which you would save you from making API requests which would be nice.

Posted in rails migration warnings

Totally fine and part of running Ruby 2.7.0 with Rails right now. They're just warnings like it says and it will be updated in Rails core shortly.

Hey Taylor, I agree that you should definitely use columns. I'm actually working on this functionality for Jumpstart Pro as we speak. 😜

Hey Ali,

This is a great question. What I would probably do for this is I would create a model that would cache the results of the API call.

Then I would use a before_action in ApplicationController to load that model for the current user. If it didn't exist, you can have it hit the API and save the results in the model.

The first request, the model shouldn't exist, but every time afterwards it will so you won't have to hit the API every time.

I wouldn't use the after_authentication hook exclusively just because there may be situations that come up where that method doesn't succeed and a user might not have any results. Imagine that external service went down for an hour or they returned a 500 error for some reason. If you do it every request instead, you can always hit their API as needed without worrying about missing records ever.

Sounds like your MySQL server isn't running. Try starting it again.

Posted in How to version model validations for an API?

The reason APIs are versioned is because you can do these validations on the API level rather than in the model. You would say that in v2, we'd ignore the a parameter now, even if you still submitted it.

I'd recommend checking out some of the Stripe blog posts on API design. They have done a fantastic job of explaining how they do it.

And Stripe's APIs are by far some of the best designed for handling changes safely that don't break customer apps.

Posted in Reducing Transfer costs with AWS S3

That was fast! Also might want to look into Spaces' CDN.

Curious to hear how things go and if it helps keep costs down over the next few weeks.

Posted in Reducing Transfer costs with AWS S3

That's quite a lot. You probably are spending unncessary money doing this anyways if you're creating different sizes of images since you'll be downloading them from S3 after upload, creating your sized versions and uploading those back. That probably is extra cost. Spaces should be cheaper all around since it's not going to be going across the internet for that. Plus, Spaces is just cheaper all around.

$5/mo for Spaces includes 1TB of outbound traffic, so that may help by itself.

I don't know Cloudfront's pricing, but it may save some or add to the cost. It's going to be caching your files around the world with Cloudfront, so it's faster. If they're still charging you for bandwidth out, then may just be more expensive to use that.

You probably want to do some checking to make sure you're serving up the smallest images as much as you can and almost never serving the original upload. May want to add image compression as a step in your image processing as well. Possibly using Cloudflare's free CDN would help save some of the costs too if images can be cached in their CDN.

ActiveStorage isn't super great for this since all the requests for images go through Rails rather than being served directly from the S3 url. Rails 6.1 is going to have some official ways to link to files publicly, but I know there are a few hacks you can do for now to do that too.

Transfering to Spaces should be as simple as transferring all the files to Spaces and then updating the ActiveStorage endpoint to use Spaces. They're S3 compatible so it would be pretty easy, but you'd want to make sure you didn't miss any images that might get uploaded during the transfer. That might be the harder part if you don't want to pause new uploads temporarily.

Posted in Reducing Transfer costs with AWS S3

Have you checked your AWS account's billing information to see what's costing the most?

Posted in How to setup Emails, both transactional and Marketing

Yep, usually different because they'll build different tools. Convertkit and Mailchimp will let you design and send out newsletters but they're not really built for sending transactional stuff. And the opposite is true for the transactional email providers. Nobody is really doing both well right now. That might change in the future, but it seems like it's hard to offer both types in the same product.

Posted in how to move existing body content to use action text?

Thanks Alan! I'll have to try something like this on my local copy of GoRails and see how it goes.

Posted in how to move existing body content to use action text?

Awesome, let us know how it goes! And if it works, do you mind sharing the code?

Posted in how to move existing body content to use action text?

Yup, I had the same thing. I want to convert the GoRails forums over to it but now I'm like shoot...this is gonna be a lot of work to get right.

Posted in how to move existing body content to use action text?

That's a good question. I believe you'd have to convert your old content to HTML, then save it in the associated has_rich_text object. ActionText has its own model, so you would just create that record and that should make it available.

I haven't done this, so I don't have any code to point you in the right direction unfortunately.

Posted in Pipe convert out to Convert Input Minimagick

With a gem like image_processing, I believe you would just make two calls to do this. The first would want to save the output to the file so that the second could operate on its output. That way you won't have to use pipes in Ruby.

Very cool!

Since these aren't subscriptions, I don't believe you will be able to use Stripe Invoices or any of those features. Those I believe only work for subscriptions, so I guess that you will want something like this instead:

  • Reservation model with the due date.
  • One (or more) Payments related to the Reservation. This way you can keep track of the deposit and the final payment related to it.
  • Create the reservation after the payment is successful.
  • Email them reminders in a cron job about their upcoming due date and remaining balance (if any).

That's probably what I would do. Nothing too fancy.

What happens if they don't pay the balance? Do you just remove their access or something?

If these are subscriptions, Stripe Invoices have a "days_until_due" option.

If they're not subscriptions, I would just create a record to keep track of the order and the due date. If the current date is past the due_date, then you know it has elapsed.

You can then use a cron job to email the user warnings if it's 7 days till deadline, etc.

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.