Chris Oliver


234,960 Experience
17 Lessons Completed
256 Questions Solved


ActionText uses attachable_sgid from the Attachable concern. That's covered in the @mentions in ActionText video on how that works.

I don't know how you differentiate between the two, but this works for rails app:template

after_bundle do
  p "hello"


There's probably some way to check if it's a new app and only run the last two lines if needed. Maybe by looking up the current generator name or something. I'm not sure.

A quick test applying an empty template to an existing app looks like it doesn't trigger bundle install for these. Just new apps. That may be a difference between the two that isn't documented.

The code I did find was here:

There's a run_bundle mention in there which leads me to this:

You can probably add run_bundle to your template to make sure it runs it. I would assume this would also trigger after_bundle code as well.

Unfortunately, ActiveStorage isn't currently flexible enough on the processing side of things.

You'll be better off using Shrine if you want to do any transcoding right now (unless you pay a service to do transcoding for you). I've used streamio-ffmpeg with Shrine to convert videos before.

Posted in Bidding App

Hey Ryan,

I would probably create like a Bid model that kept track of these. Since you don't want to charge until the very end of the auction, you'll want to keep track of the bid history and then charge the winner (or runner up in case something falls through, etc).

Then you'd just add validations to check against previous bids for the product and make sure they're $25 more than the last.

Posted in Rails & Vue.js Trello Clone - Part 4 Discussion

Have any information on that? It looks like the Draggable docs (, search for "onEnd") show the following object.

    // Element dragging ended
    onEnd: function (/**Event*/evt) {
        var itemEl = evt.item;  // dragged HTMLElement;    // target list
        evt.from;  // previous list
        evt.oldIndex;  // element's old index within old parent
        evt.newIndex;  // element's new index within new parent
        evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
        evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
        evt.clone // the clone element
        evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving

It's been a while since I did this, so if this changed, then it may need a couple tweaks to match up, but at least here you have information on all the properties from the event.

The recommended place for stylesheets in Rails 6 is still the asset pipeline. Tailwind is a css framework generated by JS so it needs to be more tied to things than Bootstrap.

This is all just side effects of whats going on in modern frontend. Rails is just trying to make that easier, unfortunately it is pretty messy I think, but its also doing more complex things now.

Yup, exactly that. Match haml files instead of erb.

Posted in How add PurgeCss with TailwindCss?

Hey Nikola,

I just posted an episode on this yesterday:

Posted in Active Query: object date within the next 30 days.

Yeah! Aren't they handy? It just makes your code so much more readable later on.

Also, another small pro-tip is you can do a scope with an argument like so:

scope :in_next_days, ->(amount) { where("cutdate BETWEEN ? AND ?", Date.current, amount.days.from_now) }

This would let you call Node.in_next_days(30) and pass in the length of time if you wanted the next 7 days or something different.

Posted in Active Query: object date within the next 30 days.

Hey Matt,

You're almost right. You just need to find things between Date.current and 30.days.from_now so you don't query for the exact day 30 days out. That way you get everything between now and then.

@nodes.where('cutdate BETWEEN ? AND ?', Date.current, 30.days.from_now)

And you can make that a scope:

class Node < ApplicationRecord
  scope :upcoming, ->{ where('cutdate BETWEEN ? AND ?', Date.current, 30.days.from_now) }

Posted in How do I add HTTParty to ActiveJob ?

Hey Arnas!

Anytime you see a ROLLBACK in your logs, that means your validations failed.

In development, you print out what errors there are if it fails for debugging pretty easily.

If this is happening in production, you could change to find_or_create_by! so it throws an exception instead instead of silently failing. Then at least you can debug it through your error tracking.

Posted in Setup Windows 10 Discussion

Hey Arnas,

Your Postgres server isn't running. I think most people have the best results installing Postgres on Windows and running it there, then having Rails from WSL connect to that.

I haven't actually used Gitlab's CI, but it's close.

So you don't need a master.key file as long as you have the RAILS_MASTER_KEY environment variable. Rails will check for the env var first and use that if it exists, otherwise it falls back to the file.

You should be able to set the env var using Gitlab and then you'd just need to make sure the env var from Gitlab is accessible in your docker image.

No need to write anything to master.key this way.

Hey soykje!

Rails will actually look for the RAILS_MASTER_KEY env variable, so if you just set that you should be fine. Saves you from the trouble of trying to write that out to a file and you can just set the env var like any other environment variable through docker.

Posted in How do I add Zurb foundation-sites using webpacker?

Hey Jason!

For the most part, you'll just follow their instructions which is usually yarn add package and an import or require of the package in your application.js.

There's nothing special to using things now because we're just using Webpack for everything which most all Javascript modules have instructions for on how to use. You can just look for Webpack instructions and follow those almost every time. 👍

Posted in How do I add multiple subscriptions to one user ?

Yeah, you can't subscribe to the same thing twice. You can use quantities if you need something like that.

Posted in How do I add multiple subscriptions to one user ?

Hey Arnas,

Try changing it so you have a Subscription belongs_to :user and a User has_many :subscriptions. Then use the association to handle the subscriptions in your app.

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.