Chris Oliver


271,720 Experience
28 Lessons Completed
296 Questions Solved


Posted in Ruby question - Generating a nested hash with group_by

Sounds good! It sometimes just takes a little bit of mapping out what you've got vs where you need to be and then the pieces start falling together.

Posted in Ruby question - Generating a nested hash with group_by

A nested hash could work. You could also do an array since you could use the index to determine the month too. For example, 1 -> January, 2 -> February, etc.

How do you currently know which months to remove? Is it a word as a string ("January") or the number of the month like 1,2,3?

You can use I18n.t("date.month_names") in Rails to translate to and from the names and integers.

irb(main):001:0> I18n.t("date.month_names")
=> [nil, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

Posted in Ruby question - Generating a nested hash with group_by

Hey David,

What's the final result has that you're trying to accomplish? It would allow for more concrete steps on solving the problem.

Are you trying to make something like:

{ 2017 => [4583.33333333, 4583.33333333, 4583.33333333..., other months], 2018 => ... }

And then delete certain months in the array? or something else?

Posted in Datatables From Scratch Using Hotwire Discussion

I just used it for the first time yesterday on a button_to.

<%= button_to 'Delete', @resource, method: :delete, form: { data: { turbo_confirm: 'Are you sure?' } } %>

Posted in Hotwire and iframes?

Not really a Hotwire thing. You'd have to use postMessage to communicate between the two I believe.

Posted in Datatables From Scratch Using Hotwire Discussion

TIL! Thanks!

Posted in How do I take over an existing code base?

Lots to think about! For me, the most important thing is to understand the database models and what each one's purpose is. Then it's helpful to know the different flows users will go through to better understand the controllers and views. If you can get a good understanding of that, you're going to be able to piece together your understanding of the app a lot quicker than if you have to figure it out on your own.

Posted in How to use ESBuild in Rails with JSBundling Discussion

Haha! I know right? So happy with how fast my deploys are now.

AWS should provide a webhook that you'll need to listen to once the file is finished transcoding. You can use that to trigger a broadcast of the final video with Turbo.

Transcoding is a messy art though, so I would recommend trying out something like Mux, Bunny Stream or Cloudflare Stream if you can. They usually do on-the-fly transcoding so you can instantly embed the video which is really nice. I believe you can do the same with AWS too, but it's the usual digging through config and docs to figure out how to do it.

Your node version is too old (see the webpack-dev-server line)

Expected version ">= 12.13.0". Got "10.16.3"

Posted in Use .ENV instead of Secrets.yml for keys

Rails 5.2+ switched to using Credentials instead of secrets.yml. I would recommend using that going forward.

That said, if you still want to use .env files, You can use a gem like Figaro to load the .env in development.

Posted in Sharing Cookies with Subdomains in Rails Discussion

Cookies are shared between them all, so yes it would.

Posted in How can I whitelist an heroku app for external api?

I'm not sure about options for Heroku, but when you use a VPS (like DigitalOcean) you get a static IP for your server (as long as you don't destroy the server).

You can also get a Floating IP that allows you to swap out the server behind that IP seamlessly so the IP does not change. That's what I use for my apps that I deploy with

Thanks for joining me Kasper!

Posted in How to use Action Mailbox in Rails 6 Discussion

You could write a filter to try to skip those, but yeah that's generally something you have to always deal with having this feature.

Posted in Esbuild

I noticed the sassc-rails gem will enable itself in production if there is no css_compressor set. You might set css_compressor = nil and see if that fixes it.

Posted in error in rake db:create command

Like the error says, your postgres server is not running. You need to start your postgres server and then it can connect.

Posted in Finding video

The other episodes in the series are Pro episodes. That's why they're only previews on YouTube.

Hey Tommy!

You would probably need to do this with wildcard URLs and then parse them.

# At the very bottom of your routes file so it doesn't override other GET routes
get "*place" => "places#show"

This should assign params: { place: "walkable-places-in-europe"}

And you could parse that string with Regex or similar to get your filter and location out of it in the controller.

Posted in Nesting resources & controllers best practice

I almost always nest them in folders. It's very helpful when your app grows. Often times you might have 2 or 3 controllers with the same name that do different things and the nesting in folders helps separate them out.

For example,

websites/pages_controller might be for website editor
subdomains/pages_controller might be for people viewing the website
admin/pages_controller might be for the business owner (you) to do customer support

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

© 2022 GoRails, LLC. All rights reserved.