Chris Oliver

Joined

295,230 Experience
96 Lessons Completed
295 Questions Solved

Activity

Posted in Stripe's new Billing feature explained?

My idea was basically a way for you to visually map out a product and all the different tiers for it. You can set upgrade rules and so on between them. That's basically what Stripe just rolled out. Plans are attached to Products now and you can add multiple plans to a product.

https://stripe.com/docs/billing/subscriptions/modeling

Posted in Running multiple Rails versions

Yep, it's right. The last version number is a patch version for security and bug fixes. You always want the latest version of that.

The first two versions are the ones that change and break things, so those are the ones to worry about being correct.
Rather than doing something complicated with RPC and all that, why not just have Server A make a POST request to an API on Server B and C? You could simply POST the same data changed over to those and make the same update. That's what I would probably do.

Posted in Sortable Drag and Drop Discussion

Hey Seph! I did a whole series on it here: https://gorails.com/series/vuejs-trello-clone-in-rails

Hope you enjoy it!
I personally store a local copy of all the information I care about. You can pretty easily sync this information and it's going to make your app a lot quicker not having to hit the API for every page view that needs that information. Stripe doesn't change their data structures very often so you should be fine syncing it. You can also use webhooks to keep it up-to-date.
Hey Victor,

The Carrierwave docs cover this here: https://github.com/carrierwaveuploader/carrierwave/wiki/how-to:-do-conditional-processing

You just want to check if it's an image before running the resizing and it's pretty easy to do. πŸ‘

Posted in Single Responsibility Principle Discussion

Thanks Ron!

Posted in Single Responsibility Principle Discussion

We will finally be diving into testing this year soon. πŸ€“

Posted in Improving In-App Notifications Discussion

Hey Thato,

You can simply just call that function on the turbolinks:load event (or DOMContentLoaded if you aren't using Turbolinks).

It's as simple as doing something like this:

document.addEventListener("turbolinks:load", function() {
getNewNotification()

})

Posted in The Params Hash Discussion

πŸ™ŒLet me know if there are any other basics you'd like me to cover in-depth like this!
What part of the blogs needs to be realtime?

Posted in Devise Secret Key was not set automatically

So your RAILS_MASTER_KEY is an environment variable you add to the Heroku admin in the Environment Variables section. You don't ever want that in your repository.

The secret_key line needs to go in your initializer replacing the one you manually added.

Posted in Devise Secret Key was not set automatically

In Rails 5.2, you have the new credentials file and you must set your credentials secret_key_base to the Devise secret key.


config.secret_key = Rails.application.credentials.secret_key_base

You'll need to put your RAILS_MASTER_KEY env variable in as well so your app can decrypt the credentials file.

I'm guessing they'll fix this in a new release soon, but for now this is the solution I used. πŸ‘

Posted in Render partial via AJAX without JQuery

Yep, the Rails forms use Rails.ajax automatically now and you can also trigger it manually if you want like if you were trying to build infinite scroll pagination for example.

Posted in Rails Application Templates Discussion

Hey Gustavo,

Sounds like your Redis instance on Heroku has a maximum number of connections. You might need to reduce the concurrency on Sidekiq or something to create less Redis connections (or increase your Redis node).

Posted in Render partial via AJAX without JQuery

In that case, I would highly recommend checking out Stimulus JS. Rails has the Rails.ajax helper method to handle AJAX, and you can insert the results in to the page like you're doing. Then Stimulus can handle any interactivity you might want with it. It's about the simplest way of building interactive things I've used. You'll like it!

Posted in Render partial via AJAX without JQuery

Just because Rails isn't using it, doesn't mean you should think it's going out of style. It's still used by like half the internet lol. Feel free to use jQuery especially because there are so many libraries that use it. If you choose not to, you can't use any of them and have to find alternatives or build things from scratch. 

With methods like insertAdjacentHTML becoming more cross browser compatible, jQuery just isn't as needed anymore. It was mostly designed as a compatibility layer to make things easier across browsers. That's why Rails said well, it's probably good enough to drop the dependency and simplify our framework a little. Less dependencies is usually good.

You also have Babel which lets you write modern Javascript and it compiles down to backwards compatible JS. This is kind of a different approach to what jQuery does and is what everyone uses for building Vue, React, Ember, etc apps. The nice part here is you get the compatibility but get to use new JS features (the language still sucks though 😜). 

I am leaning towards this more often and actually find using Stimulus JS or Vue to be far cleaner than my jQuery code. Stimulus doesn't have any rendering, so you'd still have to do the above, but it replaces the event handling that you typically do with jQuery. It's so nice. If you want template rendering client side, then Vue.js is awesome and is very similar. I've been leaning towards both of these over jQuery lately, but still use jQuery quite often (things like Bootstrap still require it). I mix and match right now basically.

Posted in Render partial via AJAX without JQuery

I do my best. :) 

Btw, you might want to check with that method's browser compatibility if you need IE support. I'm not sure how modern any JS methods are these days because of babel...

Posted in Render partial via AJAX without JQuery

Hey Ryan,

I believe that what's happening is that the browser doesn't know it's HTML and so it escapes the string for safety.

Here's a post on SO that shows how to insert HTML: https://stackoverflow.com/a/9851500/277994

var d1 = document.getElementById('one');

d1.insertAdjacentHTML('beforeend', '<div id="two">two</div>');

This insertAdjactentHTML method is super handy because it lets you choose where around that element the new content should go. You can see the options for it here: https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML

I think that should do what you need!

Posted in Rails Application Templates Discussion

Make sure you're using Rails 5.2 when you use the template. We're only going to support that version since it's almost released and we can take advantage of things like ActiveStorage.