Rather than roll my own URL regexes, I prefer to let the existing libraries do the heavy lifting. Ruby has a uri library which is fantastic for parsing (and validating) URLs. For example, something like this might be used in a model validation: require ‘uri’ def validate_url(url) parsed_uri = URI::parse(url) rescue URI::InvalidURIError errors.add :url, "Sorry, [...]
Tag Archives: Rails
Mass inserting data in Rails without killing your performance
Mass inserting is one of those operations that isn’t really well-supported by ActiveRecord, but which has to be done nonethless. You might say, “Well hey, I’ll just run a loop and create a bunch of AR objects, no sweat”. That’ll work, but if speed is a factor, it might not be your best option. ActiveRecord [...]
Quick tip – use anonymous blocks!
In tracking down a memory leak in one of our Rails apps today, I ran across an interesting post detailing the difference between anonymous and named blocks in Ruby, and the performance differences therein. It’s definitely worth a look, especially if you’re running in a complex environment, where new closures will be large and unwieldy. [...]
Re: Simple RoR+MySQL optimization
I recently ran across a rather bare post espousing some generic “optimization” techniques for Rails apps. It offered no education, no explanation, no benchmarks. So, I thought, why not put those claims to the test?
Powerful, easy, DRY, multi-format REST APIs
Rails’ baked-in REST support is great. Build your app right, and you can expose a programmatic interface to your users for free. That said, many times providing views in non-HTML formats tends to be bulky and unwieldy. You end up with either very brittle representations of your data, or extremely bulky respond_to blocks in your [...]
Jabberish: making Rails talk back
Ever wanted to do IM from Rails? xmpp4r-simple makes it really easy to talk to Jabber clients (such as Google Talk users) from Ruby, but it’s not quite a cut-and-dried solution for your Rails apps. Fortunately, there’s Jabberish. Jabberish is a DRb-backed Jabber client designed for use in multi-server Rails apps. Just drop in the [...]
site_config – painless custom configuration for your Rails project
site_config is a little plugin that addresses a problem lots of people seem to need to solve in their Rails apps: per-environment configuration variables. It’s very simple, but makes configuration dead-easy. To install it: script/plugin install git://github.com/cheald/site_config.git Once you have it installed, check out config/site_config.yml – there’s your config file. You’ll notice that it has [...]