Activity
Posted in best way to validate URL
You'll definitely want to do some parsing and validation. For example, leaving out the protocol happens all the time where someone might type in just
gorails.com
into the field. The protocol is important, otherwise you can print out a link that ends up being relative on accident likehttps://gorails.com/example.com
. You see this stuff all the time when validations haven't been written properly.You can use the url input field type to have the browser do a little verification. This will help with the frontend validation since it should require users to type in a protocol like
http://
at the beginning. Here's how to use that url field: http://apidock.com/rails/ActionView/Helpers/FormHelper/url_fieldServer side, you could simply require all the urls to have
http://
orhttps://
at the beginning. That's nice and simple, can do that with regex or just plain Ruby. Easy to maintain. The Coderwall link Enrique posted is a great example of an implementation like that (although it looks like it has a couple small issues). It basically uses Ruby to parse the URL and verify the protocol. That's important because simple regex checks can't verify the TLD at the end of the domains easily. There are infinite number of TLDs now, and it's going to be best to rely on the Ruby standard library for this because it will always get updated behind the scenes and you have no external dependencies.Now all these methods: regex, URI, gems, etc are all going to be approximations. If you truly want to make sure the URL is 100% valid, the best way is just to simply make a request server side anytime the URL changes to request the status code for it.
require 'open-uri'
open("https://gorails.com").status
=> ["200", "OK"]
As long as you get a 200 status, then you know the URL is truly valid. You can't do anything more accurate than that, but it's also going to slow down your server response somewhat to request the page. Worth considering how important it is to have 100% correct because you're trading off server time vs correcting a number of errors on user input. It probably depends on how often you see mistyped URLs. You could also make an AJAX endpoint that does this to improve validations client side when the user is typing so it doesn't have to significantly delay server side validations.
I definitely will. I also need to learn some around Swift and Android so that I can make some example apps using the Turbolinks adapters. That might mean we'll have a GoRails mobile app at some point. :)
I've found that using Segment.io for managing those external libraries helps a lot. It makes that management a lot easier, but I also intentionally use very few third-party Javascript libraries because they can quickly slow down the frontend performance of a site. You might check out Segment and see how it goes.
Hey Pete, this usually happens from one of two things:
1. You're using a third party library (like Segment.io for example) that isn't compatible with Turbolinks events by default. These usually require some tweaking in order to make compatible. It all depends on the library but there are usually ways to do it. You can google for that library + turbolinks and see if anyone else has made it work, or if you can tweak it yourself.
2. Sometimes it can just be a simple setup issue if your JS is running incorrectly. Maybe you need the jQuery.turbolinks adapter, or just to modify your code slightly to allow running on multiple pages.
It all kinda depends on your code and the issues you're experiencing. They can be kinda hard to track down so the easy solution is to turn off turbolinks for those links in the meantime if you can figure it out. I don't think there's anything wrong with that so you can figure it out later.
Heck yeah man! :D
Posted in GoRails speed
It took me a little while, but I did it! https://gorails.com/episodes/gorails-performance?autoplay=1
Good news! Heroku is actually really easy now.
Just tested it this morning and it's super easy to setup: https://github.com/excid3/a...
The trick is that you _must_ use the route mounted version because Heroku apps only expose one port. Just make sure you have a Redis connection added, and you should be all set.
You can try out my example app here: http://actioncable-gorails.... (just make sure you're on http, not https.
I haven't yet, was hoping that the first release candidate would ship, but still waiting on that. I put these episodes out and then like the next week a bunch changed so I didn't want to be making too many immediately outdated episodes.
Posted in GoRails speed
The memoization one is definitely up this alley. One really good example use case (that I realized after recording that episode) was that when you want to sync records from an API, memoizing the results so you can save / update copies in your database is really helpful.
I'm going to do another episode talking about all the things I use on GoRails, but that's definitely one of the tactics.
Posted in Deployment Question
Feel free to post it here so other people can find it and the solution. Which version did you upgrade to? 3.4.0?
Posted in Deployment Question
The Rails version doesn't matter because the error is in Capistrano and there's a missing compatibility thing somewhere internally.
Posted in Deployment Question
You might want to update to the latest Capistrano. https://github.com/capistrano/capistrano/issues/1641
Posted in How to add logo image to mailer
Ah cool. I've used https://github.com/cyu/rack-cors in the past to do that, but then I just started paying $50/yr for Typekit and no longer have to deal with that for almost any fonts I could want to use.
Posted in How to add logo image to mailer
Oh fun, CORS is not a super fun thing to mess with. I'm not sure if you can do that with email, but you have to allow origins with CORS to determine where your fonts can be loaded from: http://stackoverflow.com/questions/27726802/css-font-being-blocked-from-cross-origin-resource-sharing-policy
Posted in How to add logo image to mailer
You should just be able to use the regular old <%= image_tag("logo.png") %>
helpers just like you would use in your views. You may need to set your asset_host so that it includes a full URL for the images in the emails since they aren't displayed in the browser under your domain.
# I believe these should do the trick:
config.action_controller.asset_host = 'http://localhost:3000'
config.action_mailer.asset_host = config.action_controller.asset_host
This looks like a fun project! If you've already got elasticsearch going, it'll do really well to handle the search queries (plus it should handle the ordering from closes to furthest as well). Curious to hear how it goes man!
I would probably use the Geocoder gem for this. You can back it with interchangeable APIs and cache results in Redis which is really handy.
Have you considered using the geosearch that's built into ElasticSearch? You can pass it in either a bounding box (like the coordinates of a Google Map embedded on the page like Yelp does if you drag the map), or you can search within a radius, so you can easily find things by km or miles away.
What's your UI going to look like for the interactions?
Templates are a definitely interesting topic. I spent some time making templates in the past and I believe I ended up trying a couple different things. One approach I had a templates table, but it felt like there was a lot of duplication going on (two tables, same columns for example). The other was to mark records as templates and we'd just copy a few fields over to the new record. That ended up working better for what we were doing because it was pretty simple.
I personally like just operating off an existing record because you can just say "Okay, let's dup this, including it's children, but only keep these certain fields, strip out these others" and you don't have to deal with creating multiple tables or anything.
If you go that approach, you can use the .dup
method on the instance, so you'd load up the original and then call .dup
on it which should generate a copy in memory without an ID attached. You might also need to loop through associated records and dup those as well for the new model. Then you can clean any of the fields you want by setting them to nil or whatever.
The other approach for this same thing is to take the attributes from the original, use except
on the hash to strip out those fields, and then create a new record like you normally would in the controller. Either way is effectively the same, this one might be a lot more familiar to most people. .dup
wins if you don't need to strip out any fields though because everything's already set automatically.
Posted in Memoization Discussion
Yes, great point! Thanks for mentioning that.
Posted in Subscriptions with Stripe Discussion
Double check that the authenticity token is being submitted in the params. Your screenshot looks like it isn't being included. It might be not making a POST request and just doing a normal GET, which isn't what you want.