Rails Reading - Sept 10, 2009
Relevance Blog : Keep Models out of Your Views’ Business! (Part 2)
Last week, I wrote about using Rails’ I18N facilities to break dependencies between your models and views, by changing how model and attribute names are displayed. But there’s another place where the implementation of models sometimes peeks through into views: validation error messages.
Depending on how you use them, Rails’ error message helpers may insert attribute names into messages, and the changes from last week will take care of that automatically. But it goes farther than that. Often, validation error messages express things in a way that is not appropriate for end users. The usual solution is to override the default messages with :message => ‘…’ options on the validation declarations. But again, that means the model is actively involved in presentation issues, and we’d like to avoid that if possible.
Testing binary downloads with Webrat : Witold Rugowski aka NetManiac
I’m using Webrat to keep some sanity when approaching maintenance of new application. Customers often come to me with legacy code, which somehow is not covered by tests.
In such case integration tests are way to go, since they provide most bang of Yours bucks - each written test could cover many parts of application.
DBpedia is a community effort to extract structured information from Wikipedia and to make this information available on the Web. DBpedia allows you to ask sophisticated queries against Wikipedia, and to link other data sets on the Web to Wikipedia data.
I’ve been plotting to make the git and GitHub setup process a bit easier for new users, so I spent a small portion of my labor day weekend actually doing some labor (the horror). You can see the results in this repo.
Improve the speed and security of your SQL queries | Zen and the Art of Programming
An easy way to improve the performance and security of SQL queries is to replace literals with parameters. By replacing literal values with parameters, advanced relational databases will be able to compile your queries and have their execution plans cached. This saves time and precious resources when the same query (minus the actual values) is executed over and over.
True, False And Nil Objects In Ruby
Every expression and every object in Ruby has a boolean value, which means that every object and every expression must either evaluate to true or to false. This makes true and false rather special values. But, they are not just empty value or simple keywords, just like with everything else, both true and false are Ruby objects.
I spent most of my summer developing a social web application for the salsa dancing community in Montreal. I realized this project in part for fun and in part to seek new business opportunities. The application relies heavily on Facebook Connect for authentication and events management. Now that the website is mostly done and online, I want to share my experience developing with Facebook Connect.
Carsonified » Web Conference Survival Tips
Attending a conference is a lot of fun but it’s important to make the most of the opportunities that present themselves. It’s easy to be unprepared and having learnt the hard way here are a few of my “web conference survival tips”.
Rails Caching And JavaScript Techniques | Vinsol
While implementing caching in a recent rails project I came across some typical caching issues. In a lot of pages the content is same for all users but certain components in them have user specific actions. As an example, I have a page listing all public messages that users have posted(similar to the public timeline in twitter) but actions on those messages are user specific(eg: only owner or admin can delete a message). Also, most of these actions use ajax and the rails authenticity token in them also gets cached resulting in subsequent failures if the session changes. Another issue was that the timestamps in most pages is fuzzy and they become irrelevant if a page gets cached for too long. I could have created separate caches for each user but if the user base really grows managing the caches would become a nightmare and that would still not solve the authenticity token and the timestamp problem. The simplest solution was to use JavaScript, more specifically jQuery.
Shades of Gray: eval() Isn’t Quite Pure Evil
I agree it’s sometimes worth avoiding eval(). However, I think we need to admit that it’s sometimes OK to use eval(). The trick is to ditch the fear and rationally evaluate which of the two you are facing.
Robby on Rails : Planting the seeds
Yesterday, the Rails team released 2.3.4, which includes standardized way for loading seed data into your application so that you didn’t have to clutter your database migrations.
I noticed a few comments on some blogs where people were asking how to use this new feature, so here is a quick runthrough a few ways that you can use it.
Rake Routes Review Repeat [Article] « elc technologies
If you have a large and active project with many, many nested routes you’ll find that listing routes using rake:routes usually ends up a mass of info spewed into terminal that is painful to wade through even with grep.
It became a pain for me and I decided to take a stab at extending rake:routes to add a task to simplify the output and add some new information. Most of the time I grep rake:routes to confirm a path name or to see if I’m missing a route. Some of the time I wonder about whether there are orphaned routes or whether there are missing controller methods. It would be nice to get some help on these too.
So I put together a rake task for routes that you can drop into lib/tasks/routes.rake to get more succinct output.
>>rake routes:by_controller
Ask A Rails Tester Person | Pathfinder Software Development | Blogs
It’s time to play “Ask A Tester Person”, where I answer questions that I’ve gotten via email or otherwise about Rails Testing topics.
Rails Magazine Issue 4 Now Available
Issue 4 of Olimpiu Metiu’s Rails Magazine is now available in both a free PDF download format or in print format (via MagCloud) for $6.62. Contents include:
* Background Processing with Delayed_Job
* Generating PDF with ODF templates
* Feel the Radiance with Radiant CMS
* Oracle Tips and Tricks
paperplanes. There’s Something About Legacy Code
Why do people still write code that sucks, code that’s close to being unmaintainable, code that’s so insanely tangled, code that’s untested?
The answer might be obvious or not. There’s some simple reasons, which is to say that I couldn’t come up with any reason that seems like a fair one:
* They just don’t care (gasp!)
* They claim they don’t have the time to write clean code or to clean up after themselves
* They claim that management forces them to work on new features all the time
MonkeySupport: Monkeypatching Rails with C for significant performance increases - Burke’s posterous
MonkeySupport is a brand new gem I’m working on that should give rails
a significant performance boost. It’s still in its infancy, but the
goal is to reimplement parts of rails in C, via the ruby C extension
API. Thus far, I’ve done a few of the methods in the
ActiveSupport::Inflector, such as camelize, underscore, demodulize,
and so on, with an average runtime decrease of about 75%. You can find
the code on github, at http://github.com/burke/monkeysupport .
Interfaces and the Future of Ruby | Agile101
An interesting Google Tech Talk by Yehuda Katz on the subject of Interfaces and the future of Ruby.
Rails Envy Podcast – Episode #090 – 09/03/2009 | Rails Envy
Episode #090. I’m joined today by Dan Benjamin and we have quite a fun time. You may know Dan from his compiling Ruby, Rails, and MySQL guides, cork’d, and most recently Playgrounder. Dan’s going to be hosting the podcast for a little while now and I’m thrilled to have him as a co-host. We’re experimenting with a new idea for “community spotlight” in this episode so let us know if you have a ruby/rails project launch coming up the community might benefit from.
Riding Rails: Ruby on Rails 2.3.4: Security Fixes
We’ve released Ruby on Rails 2.3.4, this release fixes bugs and introduces a few minor features. Due to the inclusion of two security fixes, all users of the 2.3 series are recommended to upgrade as soon as possible.
Exclusive coverage of Ruby Kaigi 2009 – the largest Ruby conference in Japan: photos, analysis, special guests and more…
Apart from event coverage, we have some great articles too:
- Background Processing with Delayed_Job
- Generating PDF with ODF templates
- Feel the Radiance with Radiant CMS
- Oracle Tips and Tricks
Bamboo Blog - Cucumber Tags: For Fun & Profit
Recently Cucumber added support for tagging features and scenarios which allows you to flexibly organise and categorise your features.
We’ve been able to use these tags to speed up our tests, quite considerably in some places. Once of our projects is using Sphinx (with the brilliant Thinking Sphinx), to search the database. As Cucumber tests the full stack, in order to get accurate test results we need to configure, index and start Sphinx before running the test suite.
Using Ruby Blocks And Rolling Your Own Iterators
I recently covered Ruby block basics in my post, More Advanced Ruby Method Arguments – Hashes And Block Basics. I mentioned that blocks are not really method arguments and also covered the two different types of block syntax. Towards the end of that post I promised to examine Ruby blocks more deeply and I am going to try and do that here.
Beyond Test Driven Development: Behaviour Driven Development | Agile101
A great Google Tech Talk talk by Dave Astels about the next step after Test Driven Development: Behaviour Driven Development (in Ruby).
Dave goes on to explain that “Behaviour Driven Development is what you’re doing already… if you’re doing Test Driven Development very well…
That’s Not a Memory Leak, It’s Bloat | Engine Yard Blog
A real true-blooded memory leak is rare in comparison to the occurrence of bloating Rails instances. If your mongrels (or thins, or passenger instances) are suddenly sporting 100MB or more of extra weight, look no further: we’ve got the diet plan for you!
What Is Bloat?
In short: you are loading in too much. Too much what, you ask? Why it’s too much ActiveRecord!
Latest episodes | BDDCasts - BDD Screencasts with Cucumber, RSpec and Ruby on Rails
Screencasts on Behaviour Driven Development
Talk Like A Duck : Ruby Version Management: Multiruby and RVM
There have been some tools for this for a while now. A lot of you probably already know about multiruby, and many may be aware of a new gem called rvm for Ruby Version Manager.
These two are useful for different purposes. Multiruby excels for testing ruby code against different versions, while rvm is great for quickly switching rubies so that you can play with one or the other. I think of RVM as a set of hand tools, and multiruby as a power tool workshop
benburdick’s slicehost-tools at master - GitHub
command lines tools that take advantage of the slicehost API
Sliced Software - Getting Your Existing Rails App on Facebook
There’s a ton of information already out there about writing a new Facebook app with Ruby on Rails. You use facebooker, you call a method at the top of your application_controller and you’re done. It’s pretty easy. The problem is that when you have an existing Rails app and you want to extend it to support alternate fbml views for a Facebook application, things are a bit trickier.
Sliced Software - Making Your Existing User Base Play Nice With Your Facebook User Base
In the previous article, I talked about how to use facebooker to extend your existing rails application with Facebook only views. Requests that came into your application from Facebook, were authenticated by facebooker to be genuine Facebook requests, the Facebook user was required to add your application and all of your Facebook specific .fbml.erb views and layouts were automatically used instead of your standard .html.erb views. While all of this was happening for requests coming from Facebook, your regular application kept chugging along, doing its own thing, unaware you were cheating on it with that blue haired girl from your Calc class.
Riding Rails: A Month in Rails
Lots of great content coming out of the community in the past month. Below you’ll find some of the most useful tutorials and libraries I’ve found over the past few weeks. These stories came directly from the Ruby5 podcast, which covers news from the Ruby and Rails community twice weekly.
acts_without_database: Now a Rails Plugin | Pathfinder Software Development | Blogs
Quite a while ago, I wrote a blog post which included some code which allowed you to use ActiveRecord without needing a database table.
I recently needed that functionality again, so I converted that code into a plugin and put it on github so that I could easily include it in another project. While doing this, I also cleaned up and simplified the code quite a bit.
Coming Soon: The NoSQL Series | Viget Extend
We’re always excited about new trends here at Viget, and the most recent phenomenon that’s caught our attention is NoSQL - the reaction against traditional relational databases like MySQL. The movement has been characterized by an explosion of interest in key-value stores, document-oriented databases, and other (mostly non-relational) alternatives for data storage. Several of the developers here in the Labs have been experimenting with these emerging systems, and over the next few weeks, we’ll be posting our thoughts.
Amazon Wishlist RSS, Ruby and Signing/Authenticating your Requests
OK so you don’t actually care about all the crap you just want the guts. I took the basic structure from ruby-aaws. Look there if you want a complete library. Here’s how to sign your Amazon requests using ruby code.
Phusion Passenger 2.2.5 released « Phusion Corporate Blog
Phusion Passenger is an Apache and Nginx module for deploying Ruby on Rails web applications, and is mainly focused on ease of use and stability.
Relevance Blog : Keep Models out of Your Views’ Business!
Does this mean Rails’ implementation of MVC is broken? Not at all! My favorite definition of “architecture” in software is “the set of decisions that will be hard to change later.” And the best architectures are the ones that keep that set small, allowing developers to move quickly without fear of being boxed-in later in the project. Rails uses its default behavior to let you move quickly, but leaves your options open for changing that behavior later.
Building tiny Web-applications in Ruby using Sinatra
Sinatra is not a framework but a library i.e. a set of classes that allows you to build almost any kind of web-based solution (no matter what the complexity) in a very simple manner, on top of the abstracted HTTP layer it implements from Rack. When you code in Sinatra you’re bound only by HTTP and your Ruby knowledge. Sinatra doesn’t force anything on you, which can lead to awesome or evil code, in equal measures.
Eric’s Archived Thoughts: Diagnostic Styling
On stage at An Event Apart Chicago, I made reference to recent efforts I’ve been making to develop a set of “diagnostic” styles. I’d hoped to have them ready for presentation in Chicago, but didn’t get it done in time.
Well, they’re still not really done, but as I’ve now torn them apart and rebuilt them three or four times, with no real end to that cycle in sight, it’s time for me to get them off of my hard drive and into the public eye. It’s a little bit complicated, so rather than post the whole thing in this entry, I’m going to link to a demonstration page. I first want to say a few things about it, though.
RubyPulse :: Episode 0.5 - Ruby Version Manager (rvm) - “Cut Rubies with ease…” - wayneeseguin
“Cut Rubies with ease…” - wayneeseguin
Riding Rails: Gem Packaging: Best Practices
When you call load or require a new file, Ruby searches through the files in its load path. This allows you to require files relative to the load path without specifying the files full system path.
The initial load path contains paths for Ruby’s standard library. There are three aliases that point to Rubys global load path array: $:, $-I, $LOAD_PATH. You can append or prepend you own libraries to this list. The load path can also be modified from the command line with the -I flag.
Potion Store is an open source Ruby on Rails application that powers the Potion Factory Store. The goal is to help new Mac OS X developers get up and running fast without having to sign up with services such as Kagi or Esellerate. The only thing you need to bring is your own license key generator and a PayPal or Google Checkout merchant account.
Rails Rumble: Micro-App Competition Winners Announced - ReadWriteStart
In 48 hours last weekend, 237 developer teams competed and generated a total of 137 qualifying web applications, all developed with Ruby and Rails on the back end.
PaulBarry.com - Infinite Recursion
A few days ago I posted an article on Tail Call Optimization. One really quick way to determine if any language/VM/interpreter performs Tail Call Optimization (TCO) is to write a function that calls itself, in other words, creating an infinitely recursive function. If the function just runs forever and doesn’t return, the interpreter is doing TCO, otherwise you will get some sort of stack overflow error. So I decided to test a variety of languages to see what happens when you write an infinitely recursive function. First up is ruby:
Collaborative Filtering with Ensembles - igvita.com
While the topic of Ensembles is a rich one, the general idea is remarkably simple: instead of attempting to build one general model to capture all the subtleties of the data, use multiple predictors and combine their results.
A Wealth Of Ruby Loops And Iterators
As you may have guessed from my recent posts on Ruby method arguments (and more advanced method arguments), the Ruby case statement and others, I am kind-of discovering Ruby in my own way and looking more closely at things that I find of interest. So I’ve decided to fulfill my own wish and put together all the different ways to loop over stuff in Ruby.
[Screencast] Real Thin Restful Controllers with Inherited Resources - AkitaOnRails.com
So, I decided to make a screencast showcasing some of its basic features. Bear in mind that this gem offers a lot more and I highly encourage you to read his Wiki page about it. There are dozens of options that you can leverage to make your projects even more maintainable and lean.
Innovation Factory Dev Blog » Metamagical class variables in Ruby part 2
In my previous post Metamagical class variables in Ruby I described an oddity of Ruby causing a problem in a plugin I was writing at the time. It was about class variables that were set by dynamically defined methods. After a lot of asking around the general advise was just to avoid class variables, but I still couldn’t sleep.
Always remember me - GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS
Clearance now uses only cookies with a long expiration as its default. The effect is always remembering the user unless they ask to be signed out.
The command pattern is another one of those patterns that we all (whether we realize it or not) see almost every day. It’s commonly used in UI development but it’s a pattern that can be applied in many situations. In rails, ActiveRecord migrations are a perfect example of a command implementation, including “up” and “down” methods for applying and rolling back a migration respectively.
Carsonified » How to Create Bulletproof Sessions
In the first part of this series we went over how a cookie works and what can be done to secure them. In this section we’re going to go over ways to add additional security to the session beyond the cookie itself.
By the end of this article we will written our own wrapper class for “session_start” that protects our session from a number of attacks while taking into account some of the unique challenges presented by modern ajax-heavy websites.
Git: Your New Best Friend [Server Side Essentials]
This article introduces version control and Git without assuming you have any prior knowledge or programming experience. Because of its introductory nature, certain details are simplified or omitted and the use of the Git Graphical User Interface (Git GUI) is emphasized. Afterwards the reader should be able to use Git for basic version control and know where to locate further information.
Nginx Passenger vs JRuby on Jetty | Letsgetdugg
I am in the process of evaluating which option to choose for a new production deployment of a Sinatra application.
jruby vs ruby. Pros and Cons of the implementations:
A List Apart: Articles: Inline Validation in Web Forms
Inline validation gives people several types of real-time feedback: It can confirm an appropriate answer, suggest valid answers, and provide regular updates to help people stay within necessary limits. These bits of feedback can be presented before, during and / or after users provide answers.
Ajaxian » CSS Minification; Part 72; Alphabetizing
I recently wrote a small CSS minifier in Java that optimizes your CSS output for gzipping. Essentially, it does most of what the YUI compressor does, but additionally, it ensures that property values are always ordered consistently. This means that the gzip algorithm can reduce the file size further.
LDAP Pass-through Authentication with Authlogic and ActiveLdap « Live & Code
Today, I pushed a branch to my fork of authlogic_example: with-activeldap.
This branch shows a way of implementing pass-through authentication to an LDAP server using ActiveLdap and Authlogic, with just some small changes to the User and UserSession models.
Cassandra and Ruby: A Love Affair? | Engine Yard Blog
Most of today’s up and coming key-value stores are more than just simple key-value stores. You saw this when we looked at Tokyo Cabinet which, in addition to simple key-value capabilities, adds more sophisticated abilities, such as database-like tables. In this post we’ll look at Cassandra — a modern key-value store that continues this trend. Cassandra was originally developed by Facebook and released to open source last year. The Facebook team describes Cassandra as (Google) BigTable running on top of an Amazon Dynamo-like infrastructure.
Riding Rails: Three reasons to love ActionController::Responder
A couple weeks ago, I wrote about the newly added ActionController::Responder which summarizes your application behavior for a specified format in just one place. For example, the default html behavior is written as:
Sharing is caring - GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS
We recently described our experimental Cucumber directory convention.
Here’s another directory convention I’ve been using. Mise en place.
Ben Hughes — Software Developer
When you aren’t careful, it is easy to slip gems into your app without properly accounting for them. Often times it is simpler to just hope on system gems than mess with config.gem. This makes deployment more difficult and can make bringing a new development environment online take significant time and energy.
To fix this later, you need some idea of the gems on which your app depends. Put this snippet into the Rakefile below the boot line and run rake test | grep GEM
Devver: Run Your Tests or Specs 3 Times Faster (On A Cloud Of Servers)
Devver is a new Ruby testing service that lets you run your tests in parallel on their cloud of servers. This means your tests (or specs, both Test::Unit and RSpec are supported) could run in a third of the time as usual (depending on your setup) and it’s as easy as copying a Rakefile into your project and entering a few settings. Devver stresses that “you won’t have to alter a single line of your code.” Devver is currently in public beta.
RED is a robot that checks HTTP resources to see how they’ll behave, pointing out common problems and suggesting improvements. Although it is not a HTTP conformance tester, it can find a number of HTTP-related issues.
Welcome to the third annual 2009 AWS Start-Up Challenge. We’re looking for the most promising start-ups that can grow into significant, meaningful, and lasting companies that leverage AWS to build its infrastructure and business.
Start-ups in the United States, the United Kingdom, Germany, and Israel are encouraged to apply for a chance to win $50,000 in cash, $50,000 in AWS credits, mentoring sessions from AWS technical experts, and AWS Premium Support Gold for one year
Simplifying Rails Block Helpers (With a Side of Rubinius) « Katz Got Your Tongue?
We all know that <%= string %> emits a String in ERB. And <% string %> runs Ruby code, but does not emit a String. When starting working with Rails, you almost expect the syntax for block helpers to be:
<%= content_tag(:div) do %>
The content
<% end %>
Why doesn’t it work that way?
liveatthewitchtrials: Fair division using a spreadsheet and Ruby
Ruby has a cool library called roo for interacting with spreadsheets. So heres a program to get the data out of a spreadsheet and send it off to GLPK
Riding Rails: Upgrading to Snow Leopard
The key change for us Ruby developers, is the fact that, in Snow Leopard, all the interpreted languages (including Ruby) are now running in 64-bit by default (obviously, only if you have a 64-bit machine). For pure Ruby applications and libraries this shouldn’t pose any problems. But if you are migrating from a Leopard environment where you compiled C extensions for 32-bit only, these gems won’t properly load in Snow Leopard. Same thing goes for libraries you might have compiled in 32-bit mode and that you might want to use on your migrated system.
Finally I managed to attend the biggest of the agile conferences around. Unfortunately I missed the first 2 days which means 50% of the conference. For the 2 full days I was there I had the pleasure to attend interesting talks, knowing smart people and get a sense of how agile is doing these days. The organization was almost perfect, excluding the confusing aspect of “stages” as categorization for talks. But that’s a minor problem in my opinion. Please jump right at the bottom if you only care about the conclusions.
Jake Scruggs: Lone Star Ruby Conf 2009 Day Two Morning Sessions
More conference talks summaries
Last night Matz gave a keynote entitled “Why do we Love Ruby?” He talked about how Ruby embodies Quality Without A Name (Qwan). Here’s a description of Qwan.
I think it might be time to retire this talk, as I’ve seen it more than a few times before. I’d much rather hear about interesting problems he’s solved while designing Ruby or meditations on where the language is heading. A humble suggestion from a guy who’s very grateful for Ruby.
Writing Software not Code with Cucumber – slides from Ruby Hoedown • Blog Archive • Ben Mabey
Anyways, I just finished presenting at the Ruby Hoedown. It was roughly the same talk I gave at Mountain West Ruby conf but with a lot more advanced material and content in general. It went somewhat okay.
I’ve been reading a lot of Rakefiles lately, and it’s obvious that the folks writing them think of Rake as An Engine For Encapsulating Tasks. That’s fine, but it’s only part of what Rake can do.
This entry was posted on Thursday, September 10th, 2009 at 8:35 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


