Recent Posts - Page 17
RubyURL: new design and code base
Yesterday evening, I deployed the new version of RubyURL. This was a collaborative effort between Chris Griffin and I, which weāre happy to finally push live.
There are a few things that weāre going to push out in near future, such as an API and a new RubyGem.
Chris volunteered to work on the new design and I did most of the programming in Ruby on Rails. When we worked on this, we really wanted to keep the process as simple as possible, despite some of the problems that the site has been having.
In the end, we have a Rails application that is only 85 lines of code and has a 1:2.3 code-to-spec ratio. I wanted to keep it under 100 lines of code. This means that there is some breathing room for further development.
We also tried out a beta account that I was given for RoundHaus for Subversion hosting. We had a really good experience using their service and were impressed by the plethora of useful features that came with the repository, such as continuous integration, rcov/code coverage stats, and twitter integration!.
If you find a bug, be sure to submit a ticket on the RubyURL bug tracker.
On a side note, we deployed this on a brand new Rails Boxcar, our new hosting solution that will be launched in the very near future. ;-)
Rails Business: 'Weekly' Review #3
Itās been about six weeks since the last Rails Business āWeeklyā Review on here, so perhaps itās worth changing the name to cut me some slack on not being consistent. ;-)
Since the last post, weāve gone from around 400 members to 555 as of this morning. Weāve had 562 messages as well, so there hasnāt been a shortage of discussions taking place. Iād like to take a few moments to highlight some of the discussions that have taken place and encourage you all to consider participating, if youāre not already.
Licensing and Client Agreements
Tim Case writes,
āMy client sent me this agreement drawn up from their lawyer that
included the following:
Ā© the Contractor shall not bundle with or incorporate into any Work
Product any third-party products, ideas, processes, software, codes,
data, techniques, names, images, or other items or properties without
the express, written prior approval of the Company;ā
Tim then goes on to ask how his applies to using Ruby on Rails, which as a MIT license and how other consultancies are handling these types of situations. Follow the discussionā¦
Escrow
Gustin writes, āDoes anyone have any escrow experience, legal and cost? I am dealing with a client that got burned bad and we are reducing their fear with escrow on the first two iterations.ā
Project Planning tools
Mike Pence writes, āSo, I used to use MS Project for the composition of those dreaded Gantt charts, but it has been a few years since I had to be so formal. Anything new and exciting - and more robust than Basecamp - happening in the world of project planning software?ā
Not long after, Jim Mulholland started a new thread on the same topic and brought up the open source application, redMine. Follow this discussionā¦
Ruby on Rails versus .NET
Michael Breen asked a big question on the list, which has sparked an going discussion about the benefits of using Rails versus .NET (and other platforms).
āA couple of months ago I decided to stop actively pursuing .NET gigs to focus on Rails. Several of my existing .NET clients have learned of this through the grapevine and have contacted me to discuss.ā
Three things Timās learned from Freelancing Rails
Tim Case shared his experience of freelancing with Ruby on Rails and highlights three things that heās learned.
- The non-code business aspect of Freelancing is demanding.
- It takes 10 hours to bill 6 to 8.
- Figuring out your rate is hard.
Read the rest of Timās observations and the discussion the followed.
Client issue tracking and documentation
Jeff Judge writes, āHello all! I was curious to here how people are handling client issue tracking and documentation.ā
Several applications were mentioned for handling issue tracking and the general consensus was that there was still a lot to be desired that current options didnāt provide. Be sure to follow the discussionsā¦
Join the Community
These were just a small handfull of the discussions that have taken place over the past several weeks. If youāre an aspiring Rails freelancer or business owner, be sure to join the community and share your experiences and learn from other members of the community that are willing to share theirs.
Until next time, have fun!
What was that idea again?
While engaging in another one of our deep philosophical conversations in
#caboose, the topic of remembering that great idea that we had
before we fell asleep or at any point during the evening.
Manfred Stienstra writes, āI always think of stuff right before I fall asleep and canāt remember them when I wake up.ā
This happens to me as well, just not as much as it used to. I keep a small moleskin notebook and a pen on my bed side table and try to get everything in there as it comes up. When I open it, I see notes that donāt make any sense, which were probably after waking up from some bizarre dream. There are many business and development ideas that come up, but itās often hard to record everything.
Iām sure that there are others whoāve faced this problem. Have you come up with a working solution? If so, would you mind sharing it?
Spec Your Views
I meant to work on this post⦠oh about 7 months ago.
Way back in January (7 months ago), Jamis Buck posted an article titled, Testing your views, which gave a few tips on using Test::Unit to, as the title suggests, test your views.
While, Iām not going to rewrite everything that Jamis wrote, Iād like to show you how to test these views with RSpec. (you might take a moment to quickly read his postā¦)
In this example, Iām going to show you how weāre able to write specs for the following RHTML, which youāll notice matches the code that he wrote tests for.
Designers, Developers, and the x_ Factor
Our team is lucky enough to be in a position where we have both designers AND developers working on the same code base in parallel.
Since Ruby on Rails adopts the Model-View-Control pattern for separating business logic from the presentation layer, weāre able to give our designers a lot of breathing room to to design the interface, whether itās for interaction or aesthetic reasons. However, sometimes this breathing room has resulted in small bugs slipping into the application interface. In general, nothing disastrous, but each bug that slips into the queue, slows down the project and we want to avoid as much of that as possible.
Iād like to share a few issues that weāve seen occur on various occasions, and then show you what weāve done to avoid them happening again.
Scenario #1: The case of the changed div id, (victim: designer)
- Designer adds a few HTML elements to the page, defines an
idon a<div>tag and styles it with CSS. - A few days later, a developer needs to make some changes, tests it in their favorite browser and commits.
- Later, the designer doesnāt understand why the styling is all messed up. āIt was working fine.ā
- ā¦minutes, hours⦠go by where the designer tries to track down
the issue. āOh! Someone renamed the
idin this<div>tag. Sigh.ā - Developer apologies, but explains that he needed to do it because he needed to make it work with his new RJS code.
Scenario #2: The case of the changed div id, (victim: developer)
- Developer is implementing this cool new Ajax feature into the web application
-
The code relies on there being one or many HTML elements in the DOM with specific
idvalues defined.Example:
<div id="notification_message"> - A few days later, a designer is making some changes to the layout
and needs to restyle some of the view that this
<div>tag is defined. Designer decides to change the id to a different value for any variety of reasons. (or perhaps they changed it to use a class instead of styling it by the id). Often times, we donāt know who set the id or class⦠and many times the developers arenāt savvy enough with HTML and designers end up cleaning things up a bit. - Later, code is checked in and designer didnāt notice that the Ajax was now breaking as they werenāt focusing on just the layout.
- Day or two later, developer sees bug, āFeature X isnāt working, throwing JavaScript errorā¦ā
- Developer is confused, āHey, that was working! What happened?ā
- Developer tracks down the problem, discusses with designer, they figure out a solution. Problem solved.
I could outline a few other examples, but I really wanted to highlight these two types of situations, as our team has seen this happen on several occasions. Luckily, weāve learned through these experiences and have taken some measures to try and avoid them in the future.
Moving forward (together)
Both of the examples above, were essentially the same problem, but resulted in problems for a different role in the design and development cycle. While, Iāve definitely been the victim of #2 several times myself, I know that Iāve also been the guilty of #1. So, what can we do as designers and developers to work with each other without causing these little problems from occurring? (remember: many little problems can add up to a lot of wasted time spent resolving them)
Several months ago, I had a meeting with Chris (User Interface Designer) and Graeme (Lead Architect/Developer) to discuss this very problem. At the time, we were implementing a lot of Ajax into an application and were occasionally running into Scenario #2. We discussed a few possible ways of communicating that, āyes, this div id should NOT be changed (without talking to a developer first)!ā
Idea 1: Comment our āspecialā HTML elements
We discussed using ERb comments in our views to do something like the following.
<% # no seriously, please don't change this id, it's needed for some Ajax stuff %>
<div id="notification_message">
...
We all agreed that, while effective, it was going to clutter up our RHTML code more than any of us desired.
Team Response: Meh.
Idea 2: Reserve idās for developers
Another idea that came up, was to ask that designers only use classes and ids wold be used by the developers when they needed it.
<div id="developer_terriroty" class="designer_territory">
...
Chris pointed out that this wasnāt an ideal solution as there is a distinct case for when to use ids versus classes.. and he is very strict about adhering to the HTML/CSS standards.
Team Response: Not hot about itā¦
Idea 3: Naming convention for Ajax-dependent elements
The third idea that was discussed, was specifying a naming convention for any elements that were needed by our Ajax code. We played around on the whiteboard with some ideas and settled on the idea that weād prefix our idās with something easy to remember for both designers and developers.
We agreed on⦠x_ (x underscore), which would make an element id look
something like this:
<div id="x_notification_message">
...
x == ajax⦠get it?
While this adds the strain of typing two more characters to much of our RJS code, we donāt run into Scenario #2 very often anymore.
render :update do |page|
page[:x_notification_message] = 'Something exciting happened... and this is your notification!'
page[:x_notification_message].visual_effect :highlight
end
or in client-side JavaScript (where we also use this)ā¦
$('x_notification_message').do_something
I find that this helps our team keep a clear distinction between what
can and shouldnāt be changed in the views by our designers. Sometimes
they have a good reason to do so, but they know that if there is x_,
then they should ask one of the developers on the team for assistance in
renaming it without causing any problems in the application. It also
allows our designers to add classes to these elements, or style the id
that weāve defined.
Team Response: Wow, was that all we needed to agree on? Hooray!
This leads me to some other problems that have/may come up, but Iāll discuss that in my next post on this topic, when Iāll show you how we can use RSpec to avoid these sorts of designer versus developer problems.
If youāre working in a similar environment, how are your designers and developers working, together, in perfect harmony?
Until next time, remember to hug your designer. ā¦and if youāre still having developer design your applications, consider hiring a designer. ;-)
UPDATE: changed examples after a few comments about using div_for as another solution. (see comments for details)
YSlow and Rails performance: Getting UJS and AssetPackager to play nice
Yesterday, I started to dig deeper into YSlow and decided to pick an application that we recently launched for a client. The performance grade that I saw at first was an F, which wasnāt surprising to me because we knew that there was going to be some fine tuning in the near future.

There is a lot of JavaScript in this application and we have several files to break up stuff to make it more maintainable. However, in production, we really donāt need to send the client (browser) 19 different JS files. Weāve been using mod_deflate to compress these files, but it doesnāt solve the problem of having several connections opening to download all the necessary JavaScript. The same is true for our CSS files.
At RailsConf, DHH announced that an upcoming version of Rails would bundle all the stylesheet and javascript files into one file and compress it. Weāre running on 1.2.x for this application and decided to look at the AssetPackager plugin as a good solution to this problem.
I installed the plugin via piston and ran the following task, which is provided by AssetPackager.
89 gmail invites available!
RubyURL 2.0 on the horizon
RubyURL was a project that I built about 2 1/2 years ago as a late night attempt to see what I could build and deploy with Ruby on Rails in a night. Itās nearing 50,000 unique website links, has a Ruby gem that you can use with it, and rbot plugins.
Iāve rewritten it about three times in the past six months, to try out some new approaches, but havenāt deployed with a new version as Iāve been waiting for someone to help me with a new design. Chris has offered to help out and once we integrate his new design with it, weāll be launching it.
Everything is not great in RubyURL land though. It appears that itās become an easy target for comment spammers to abuse the site to generate rubyurls and paste those links in their spam comments. Several pissed off bloggers, forum administrators, and system administrators have emailed me to complain that Iām spamming their site. Sadly, even with a basic disclaimer on the site, they still like to blame me for their spam. Itās gotten common enough, that Iāve written a template email that I respond with that explains how the site works and that Iām not accountable for people posting links to my URL redirect tool.
You can see that itās popping up around the net via a google search.
So, Iāve been trying to think of ways to make it easier for people to flag URLs as being abusive of the site. Iāve not come up with any elegant solution that doesnāt force the good users of the site to have more steps in their process to create a basic RubyURL.
The ideal (and current) workflow:
- User navigates to http://rubyurl.com
- User pastes in long url into text box/area
- User submits form
- User is provided with new (shortened) rubyurl
- User copies the rubyurl and does what they want with it (generally⦠pastes into IM, IRC, Email, etc.)
Some people have suggested using a user system to do this, but I really donāt like that as a solution.
Another idea, which I built⦠and later removed from my new version, involved having the original url load in a frame, and then provide a way for users to flag it as āspamā, ānsfwā, or ādeadā. Then, we could provide the user with a warning that the following URL was flagged before, are you sure you want to continue? I didnāt like this as a solution in this way as it felt very obtrusive to have a rubyurl frame at the top of the browser window.
One person suggested a captcha to try and verify that the user is human, but there are problems with this.
- I really dislike captchas. ;-)
- This doesnāt prevent spammers from using the ShortURL gem, which does everything via an API.
In regards to the API, this could be enhanced by requiring that everyone register an email address to get an API key, but only solves the API abusers.
Iām starting to brainstorm some solutions that specifically help the requests made through the web. I havenāt checked the logs enough yet to verify it, but I have a strong suspicion that much of the abuse is happening through a web-based bot, not through ShortURL⦠because Ruby developers are nicer than that. (I hopeā¦)
So, I am curious⦠dear readers of my blog. How might you solve this problem without disrupting the user experience? Or, should I just stick with what Iāve got going and find a better way to respond to pissed off bloggers who think Iām spamming them?
Discussā¦
Rails Code Audit Tips - Filtered Parameter Logging
Itās been a month since I posted, Audit Your Rails Development Team and now I find myself sitting in a hotel room in Mankato, Minnesota with Graeme after a long day of walking through the documents that we delivered to our client after conducting a Rails Code Audit and Review. Our client felt that it would be a great idea to have us visit with six of their employees and walk through the various topics that we brought up in our process. Weāve been doing several of these audits recently and are thought that it would be a good idea to begin sharing some problems that weāve discovered across projects.
As much as we like to find lots things that weād recommend improving in Rails applications, we also want to make sure that as many projects as possible avoid some of these common oversights. So, expect to see more posts related to things that we find through our Code Audit and Review process.
Today, Iād like to point out a potential security problem that is often overlooked by developers and system administrators.
Log files.
Does your application request any of the following information from your users?
- Social security number
- Credit card date (number, expiration date, etc..)
- Passwords
BY DEFAULT, all of this data is being written to your production log file. Even if youāre encrypting this data in your database, request parameters (get/post) are all written to your production logs without any encryption. Log files are also notorious for having insecure file permissions, so if youāre on a shared host, other accounts on the server might be able to view them. Regardless of how secure you think your server is, this isnāt data that you want sitting around.
Lucky for you, Ruby on Rails has an easy solution to this problem! All
that you need to do is use the filter_parameter_logging method in your
controller(s). We generally add something like the following to our
application controller.
Airplane customers prefer bland food...?
Earlier today, I was booking flights for Graeme and myself as weāre heading to Minnesota soon to visit one of our clients. While purchasing the tickets on Travelocity, I was glad to know that they remember that Iām a vegetarian. However, I almost made the mistake of submitting the form with the following meal preference for Graeme.
I found it amusing that this was the default in the drop down.
One ID to rule them all
I finally decided to put my claimID to use today with the announcement that Basecamp now supports openID. This means that I can easily access all of my Basecamp project with a single login. Some of our clients have their own Basecamp projects and having everything spread around (different usernames, passwordsā¦) made it difficult to manage. I just modified my accounts on a few Basecamp sites and now see them all listed for me to navigate between.
update: Minor annoyance. This caused all my RSS feeds to break because I subscribe to each project individually. I assumed that theyād allow me to now use my openid/password for all my RSS feeds/iCal subscriptions, but they provide you some unique hash for the password. Not sure why they decided to do that⦠instead of allowing me to use my openid/pass for the subscriptions.



