Chris Oliver

Joined

291,480 Experience
86 Lessons Completed
296 Questions Solved

Activity

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.

Posted in How would you set up these plans in Stripe?

Hey Daniel!

You've hit the point where Stripe subscriptions break down I see. :) Unfortunately they don't offer anything too complex like this and it's a bit disappointing.

I like your idea on adjusting the invoices. That would be an easy adjustment each month and wouldn't be too hard.

A slight alternative to that would be to build your own custom billing system. Basically a cron job that runs nightly and processes payments for users who subscribed that day of the month (or just run payments every 1st of the month or something). You can then do the calculations and create a Charge object each time without dealing with Stripe Subscription objects at all.

You'd have infinite more flexibility this way, but a bit more work on your shoulders to manage. Kind of depends on how pricing might change in the future, but I'd probably consider doing it from scratch at this point, although your base subscription + adjustments model does a pretty darn good job of balancing Stripe Subscriptions without having to resort to a completely custom system.

Posted in Braintree Error In Production Mode

If your new.html.erb template uses the @plans variable, you'll have to also set it before you render it in create.

I would print out the error in the logs so you can view them and see what's going wrong in production. Right now I don't see anywhere that you'd be logging the error, so you'll have an impossible time figuring out what's up.

Posted in Braintree Error In Production Mode

Hey Lee,

So for Braintree, you have to check _every_ time if the result is a success or not. In your case, it looks like the create of a customer may have failed.

          result = Braintree::Customer.create(
          email: current_user.company_email,
          company: current_user.company_name,
          payment_method_nonce: params[:payment_method_nonce]
          )
      
          customer = result.customer


This is the only line that calls `customer` on an object and can be the only line your original error came from. 

So you'll need to also handle the case where Braintree::Customer.create fails. You've got it handling the create Subscription failure, but not this one.

I'm not sure as to the redirect problem though.

Posted in Rails Application Templates Discussion

Actually, I bet it's just that you're not using the latest version of Rails 5.2 (rc1 and rc2 are what I'm using). I don't think the beta will work because it looks to have changed in this commit: https://github.com/rails/rails/commit/cf56397ccd10174d94f60331e4a55ff765b3485b

"gem install rails --pre" should fix your problem or just update it in your Gemfile to rc2.

Posted in Rails Application Templates Discussion

Hey Leonardo,

If the Procfile didn't exist, I would imagine that the full template didn't run successfully. I've made a handful of extra changes since the episode so you might want to try it again. I still haven't fixed the HTTP version of it so you'll need to use the downloaded repo still.

Posted in Rails Application Templates Discussion

Thanks for the heads up! I was working on overriding the scaffolds like I mentioned in the video and this was one of the errors I ran into. I think I already fixed it but forgot to push it up.

Posted in Sortable Drag and Drop Discussion

Thanks Joel!

Some answers to your questions (not exactly in order):

1. Rails.ajax is the new replacement for jquery's ajax ($.ajax) now that Rails no longer comes with jQuery. Rails.ajax is also smart enough to include the authenticity token in every request which is why you don't have to do #3. 

3. For your code, you should include the authenticity token in the request instead of disabling the check as you'll open yourself up to security vulnerabilities by turning it off.

2. jQuery-ui may have moved sortable to the widgets folder since I recorded the episode. Things are always changing so you'll often run into little changes like that.

Posted in Recurring events with the ice_cube gem Discussion

Good work! Looks like this probably changed somewhat recently then. The gem sure hasn't been updated for quite a while so it's surprising other things haven't broken!

Posted in Create form object with has_many attribute

This doesn't appear to be maintained anymore, but there is an ActiveModel Associations gem you could use. https://github.com/joker1007/activemodel-associations

I've used it in the past for a complex form object like you're doing and you could mix this in easily with Cocoon or something to build out the child fields_for sections.

Might be worth a shot!