Jonathan Martin
Articles tagged “rails”
-
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.
-
Rails 3: Action Mailer
~ by Jonathan Martin
As a result of designing this blog, I’ve come to appreciate the refinement of Rails 3, and the drudgery of a few “less than perfect” spots.
ActionMailer (now powered by the Mail gem instead of TMail) is an incredible refactoring of the traditional Rails 2.x email system; frankly, before Rails 3, the email system was anything but elegant — besides the clunky API, none of the traditional view helpers were available, and multipart emails with attachments were hackish.
The new system takes a huge step in the right direction by incorporating a sleek API interface and merge of ActionMailer with the traditional ActionController/ActionView. In essence, whereas before the mailer and controller/views were entirely separate entities, ActionMailer now inherits from these classes, and consequently acts much more like a traditional view. This approach hugely simplifies the design process by recognizing the similarity between HTML webpages and HTML email.
-
Rails 3: Auto Require
~ by Jonathan Martin
During the process of coding my blog, I came across the need for a truncation feature (another post in and of itself). So I made a new file under the lib directory called string.rb which added a truncate_html function to the String class. Lo and behold, whenever I called the function, the console printed an error stating that no such function existed.
In Rails 3, lib files are lazy loaded — this can be adjusted by adding the first line to the config/application.rb file. Restarted the server, but still I received the error.