Chris Oliver


255,520 Experience
22 Lessons Completed
281 Questions Solved


Posted in In-App Messages Between Users Discussion

Interesting. It looks like it does support it. I don't see that mentioned anywhere that you must use pg or mysql and their example app uses sqlite3:

Absolutely will cover that! :D

Thought it was about time to spruce up the videos. :)

Posted in In-App Navbar Notifications Discussion

Hey Ariff,

Since the notifications include two users (the receiver and the actor) you need to make sure that if a user gets destroyed, then it removes notifications on both sides. What you've written should work, except that you need to give one of the two has_many assocations a different name because the second one overrides the first one. I would rename the second to something like

has_many :sent_notifications, class_name: "Notification", foreign_key: :actor_id, dependent: :destroy

This will give you the association that can still get automatically deleted without overriding the original one. Plus we rename this one so that you can still use the common "current_user.notifications" to get the ones where you are the receiver.

I believe you'll have to make your CoffeeScript class global if you want to do that. More info on that:

Posted in In-App Navbar Notifications Discussion

I appreciate it! :)

Posted in In-App Navbar Notifications Discussion

Hey Dan! I'd change it to something like this:

Posted in GoRails Screencast suggestion: Caching

I do have an episode on Fragment caching that is helpful:

The main reason I probably won't cover query caching is because in order for your website to be always up-to-date, you'll have to query the database to find the most recent records. If you cache queries, you won't know that there are new records since you didn't make another query.

The way fragment caching helps is you make the query (which only takes a couple milliseconds) and then you look at the results to see if there are HTML fragments cached for those results. If so, you just send over the HTML fragment as a response instead. This is a lot simpler and gives you the same benefit in performance.

Posted in Subscriptions with Stripe Discussion

Awesome! I also forgot all about koudoku, so I might have to do an episode on that as well in the future.

You're using rescue without capturing the exception, so you actually lose the error that's happening. If you remove that block, you'll get the exception printed out.

I believe you can't pass a string in there like that to the new method. It only accepts integers

Posted in Display user

Hey Nick,

I believe you'll need to actually modify your autocomplete code to render HTML rather than the standard text you pass it.

Here's an example of how you'd include an image in the jQuery autocomplete library:

Basically you just have to override the default rendering code in the JS so that it can display the image tag rather than the text.

Posted in Subscriptions with Stripe Discussion

Great question and I meant to make a follow up episode talking about that. I will still do that, but here's the gist:

1. You'll need a pricing page that lists the plans. When you click on the link to subscribe, you'll pass the plan ID in the URL to the checkout page.
2. The checkout page will load up the plan based on the ID to verify it exists and is allowed (makes it easy for changing things over time).
3. You'll pass the plan ID as a hidden field during checkout
4. SubscriptionsController's create action will lookup the plan again to verify it and then submits the stripe ID instead of the hardcoded "monthly" value
5. After signing up, you'll link the user to the plan as well so you can use it for your authorization and functionality of your site that they paid for access to.

That should do the trick! I'll try and record a screencast on this very soon as a follow up.

Hmm, that's interesting. I just tried it and it's not doing that for me. There's a user with a birthday in the system as Jan 5, 1980 and it doesn't seem to find nearby results for me.

irb(main):009:0> {birthday:, 5, 26)}).count
  User Search (2.4ms)  curl http://localhost:9200/users_development/_search?pretty -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":{"and":[{"term":{"birthday":"1980-01-6"}}]}}},"size":1000,"from":0,"fields":[]}'
=> 0

irb(main):010:0> {birthday:, 5, 25)}).count
  User Search (2.9ms)  curl http://localhost:9200/users_development/_search?pretty -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":{"and":[{"term":{"birthday":"1980-01-5"}}]}}},"size":1000,"from":0,"fields":[]}'
  User Load (0.4ms)  SELECT "users".* FROM "users" WHERE "users"."id" IN (2, 1)
=> 1

Posted in How to Upgrade to Turbolinks 5 Discussion

It sounds like potentially what you want is the "remote: true" AJAX requests so that you can handle things on your own. Turbolinks won't really do anything here because the form is going to submit a POST and Turbolinks can only really handle GET requests. That's the main reason it's not going to be a good solution for your problem. I think using a JS response to the form submit should give you a lot more flexibility to do what you want there.

The JS console will show you the line of code that was the error in Chrome. That's often the best way of tracking down those little things you need to change.

You might need to modify the CSS to point to the asset-url version of the images since that's a common thing that you'll have to do. 404's won't happen with JS generally because you've got to precompile the files ahead of time, so traditionally this will come from CSS referencing images that are in different locations because of Rails.

Hey Sascha, what's the error you're getting? Normally whitespace like that makes no difference since it's "comma separated" which means that only extra commas would cause it to mess up so I suspect there must be something else going on.

What do you mean by exact match? If you've got some code examples, we can probably help out a bit better. :)

You should just be able to pass over Date objects to handle that accordingly. Integers should also be handled the same way. Normally dates and times get converted to seconds since the epoch, so you may observe that change getting automatically converted in the logs when it queries. I don't think there should be anything special.

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

© 2021 GoRails, LLC. All rights reserved.