Jonathan Martin
Articles tagged “rails-3”
-
Short and Sweet: Why You Should Use Ancestry
~ by Jonathan Martin
I know I know, it’s been close to a month since I last blogged — that’s because I’ve been working and feeling hobby-lazy on the weekends, and I’m still in the middle of writing an approximately 6–8 page (single spaced!) essay, so I’m a little preoccupied…
Okay, what’s the deal with Ancestry?
First off, it’s a slick and polished gem — strike one. Second, it addresses a very common need — strike two. Finally, it is Rails 3 savvy and efficient — home run!
In all seriousness, Ancestry is perhaps one of the handiest gems I’ve used of late. Typically, setting up trees with ActiveRecord is relatively easy — but as the model logic grows, the ease of use/implementation fails. Query calls increase recursively with every layer of the tree, and scopes have to be manually called at each layer.
-
Rails 3: Forcing SSL
~ by Jonathan Martin
Once again, I found myself beating my way through a website todo, and again I painfully managed to complete the task. Perhaps I can spare you some of that pain with this discussion of SSL.
A nice convenience with the price of two late nights spent forcing my way through the seemingly most ridiculous bugs. What objective snatched away those precious hours of sleep?
Forcing SSL. That’s it. I implemented an administrator interface to my blog so I can easily post, comment, etc. (or else I’d never get time to write) however I was bugged every time I saw the basic http auth dialog with its warning: Your password will be sent unencrypted.
Naturally, I’m a conspiracy theorist and anticipate some foreign nation overtaking my blog and using it to bring about the end of the world (ok not really). However, having to type in
https://
every time I want to securely do my magic jumbo gets really irritating, and too many times have I authenticated without SSL. Way too many times. -
Ruby on Rails: Top 10 Gems
~ by Jonathan Martin
After developing a number of Rails 3 apps, I’ve come to build up a list of “prerequisite” gems that I must install before I decide to include anything else.
Without further ado, here are my top 10 must have gems for RESTful, DRY development.
simple_form
Let’s face it: as awesome as Rails is, form building is not exactly its forte. That’s why I recommend
simple_form
, a gem that makes form partials a breeze to customize, generate, and understand. With support for native I18n, inline validations, nested models, extensive options, and unbeatable customization,simple_form
is a serious deal for forms. -
Ruby Extension: HTML Truncation
~ by Jonathan Martin
Another tip (err hurdle) I came across during the production of this blog — truncating an HTML string. Easy, right?
It seems simple enough: shorten some basic text content from a long entry. It’s extremely popular in blogs, catalogs, portfolios, etc. and with good reason — the average browser wants to find content through screening, not mass scrolling.
But a good trimmer must keep a few things in mind.
- Don’t split words
- Recognize/respect HTML tags
- Parse HTML according to standards
These add up to some pretty terse requirements once you actually get to coding. First, unless we want to manually parse HTML, we’ll have to use some standards based parser and loop through all the elements, until the specified number of characters/words (excluding tags!) is exceeded, at which point we append a user-defined tail and discard all other tags.
Update: the latest version of this handy widget is now available as a gem! Check it out at rubygems.org/gems/butter or bundle it with gem install butter.