Chris Oliver

Joined

290,710 Experience
86 Lessons Completed
298 Questions Solved

Activity

Good work man! It looks like it turned out pretty clean and simple. :D

Posted in Deploying To Production on Heroku with Puma Discussion

The free solution is alright. It provides a semi-secure connection. You're securely connected to Cloudflare, then the request gets forwarded to you, but at that point it is unencrypted. There is a possibility that someone could access the traffic coming from Cloudflare to your app that's unencrypted.

If you do need something that's fully encrypted, you'll want an SSL cert running on Heroku. That's the route I usually take because we want full encryption (and sometimes don't use Cloudflare).

Posted in Deploying To Production on Heroku with Puma Discussion

Your cheapest option would be to use Cloudflare's flexible SSL. You wouldn't have to pay for the $20/mo for SSL hosting on Heroku that way. There are some other SSL options that Cloudflare provides but I think they cost money. https://www.cloudflare.com/...

Also most places require you to purchase an SSL certificate, but you may want to check out Let's Encrypt which let's you get a free SSL certificate. https://letsencrypt.org/

Posted in Nested form and models?

I think the has_many relationship seemed good. Anything more complex sounded like it would be overkill unless you've got some other requirements to add in there.

Posted in Nested form and models?

This seems alright to me. Have you looked into the cocoon gem for making the form?

Posted in URL Based multi tenancy

Hey! Are you looking to do multi-tenancy based upon domain? If so the apartment gem is what you'll want. It can separate the database out by domain and provides some helpers for that. https://github.com/influitive/apartment

I did an episode on the Apartment gem using subdomains but you can modify that to use domains instead of subdomains. https://gorails.com/episodes/multitenancy-with-apartment

The readme for the gem shows all the relevant bits you'll need to change to support domains instead of subdomains.

As for making usernames at the root instead of on /users, you'll need to make a custom route.

resources :users
get ":username", to: "users#show"

The second route will take the /samsoft route and send it to the users show action. You'll need to make sure this route goes at the end of your routes file so that if you ever add something like /help it wouldn't think that "help" was a username.

Posted in collapse-able form feature in nested forms

Hey John!

If you're using Bootstrap, I sometimes use their collapse / accordion JS lib for this kind of thing: http://getbootstrap.com/javascript/#collapse
http://getbootstrap.com/javascript/#collapse-example-accordion

Thanks man! :)

I'll have to do an episode on jQuery.turbolinks soon. Also Turbolinks 5 as well since that should be coming out in the near future.

I'd recommend checking out jQuery.turbolinks. It's a gem that basically maps the jQuery ready function to the Turbolinks page:change function (and some others) to make all your jQuery code run as expected. It's one of those things that makes using Turbolinks a lot simpler and fixes some of the issues like this.

That should do the trick without having to write any extra code. Let me know if that works for you!

Posted in Create shopify type of Application

I would recommend checking out Liquid templates (which was made by Shopify!) for customizing the templates. http://liquidmarkup.org/

They've also got a bunch of other very helpful gems that they've open sourced which can really help. Take a look at their Github profile for those. https://github.com/shopify

Posted in Testing Turbolinks 3 partial replacement

I just was looking into Turbolinks 5 yesterday and it looks like they've ditched partial replacement because it's sort of trivial gains in comparison to the complexity it adds (their claim) and I kinda agree.

I'm curious, do you know if poltergeist is executing the JS? A previous project I was using ran tests with Firefox and that made it a bit easier to pause and debug what was going wrong with them. Often it was something like that.

And one other thing I thought of, is you can sometimes do a hybrid approach, where you don't really uses an instance of each class, but more the class as a singleton representing whatever the current object is, doing all of it's work relative to the event handler. You can have more generic React-like classes that way that end up being able to take advantage of both the class and the live handlers from jQuery.

Yeah, that's a great question. I generally take that first approach, or something like it. Sometimes rather than doing it on the response, I'll do this beforehand, but each time you'll need to instantiate the class for every record inserted. I didn't find it to be that much of an issue from building things like this, but it can be a little extra work. In any case, dynamically adding things like this without using something like React is going to usually entail some extra overhead like that.

Yo! What's happening is basically:

  • Create the new quote
  • After_save fires, attempts to schedule.
  • If that fails, you update the record, causing the after save to run again
  • If it doesn't fail, when the record does get published, you update the record, causing the after_save callback to fire once more
  • This is going to obviously throw an error on Twitter, etc for duplicate posts at some point causing your code to update the record again that there was an error, fire the after_save callback and then attempt to post again.

My suggestion here would be actually to remove the after_save callback and do this explicitly in your controller. You'll save yourself some trouble doing that. You can also set it up so that if it fails to publish, you can note the error, and schedule a job to attempt it again in the future if you would like.

So a couple things:

  1. You're calling after_save which means that if you call update_attributes, it's going to try to publish again. You'll get an infinite loop of this publishing attempt basically. Probably not exactly what you want. This is the primary issue with callbacks.

  2. What's the error message that you're receiving? It looks like you save this to the database, so I'm curious what's causing it to trip up.

I'm going to be doing some testing on Heroku to see, but I think you'll be fine using Puma on there still.

I forgot about that until after I finished recording! The actioncable-examples repository that I cloned still used the Redis adapter default, so I totally overlooked that change. Great to know.

Awesome, didn't realize they started offering that. This is going to help a lot with Twitter integrations. Thanks for sharing!

Posted in Rich text format editor in rails 4

The ghost editor looks pretty sweet too! Thanks for sharing that.

Posted in How to use devise with Adminitrate?

That definitely looks right. Huh. I'm not sure what is causing that.

One thing you could try is removing the Admin class and using AdminUser as the name instead to see if that does the trick.

Posted in How do I build conditional form fields?

For most of these, I've found that the easiest way (for me at least) is often to write some custom JS to handle it. Basically when the first thing is selected, use an AJAX request to load up some JSON for the desired subcategories and then use those to update the options available in the form. Something like this: https://kernelgarden.wordpress.com/2014/02/26/dynamic-select-boxes-in-rails-4/

I'll have do an episode on this soon, because this is a really common thing to do, but not well documented.