CrudVision - Lisa Seelye

June 23, 2007

Why CRUD? - Part 1

Filed under: crud, rails — Lisa Seelye @ 16:30

To preface: I'm going to talk a lot about my pet project, evedb.info, which is a fansite for Eve Online which seems to be stuck in a perpetual development phase. The site was written in rails as a learning project.

Like many other web developers that use a MVC model of coding I thought the pinacle of design (and by "design" I mean code design and URL presentation) was to have a ViewController that would display Agents, the Corporations to which an Agent belongs, the Stations that a Corporation owns, the Systems in which the Stations are and the Items available in the game and so forth. This meant my ViewController had a bunch of methods: agents, corporations, stations, systems, items and so forth. The URL looks like /view/agents/[name of agent]. Station names are very long so I used their id instead of their name.

When I migrated to Rails 1.2 I had a problem. Since my URLs included the names of the thing being viewed (/view/agents/Hoken+Isikesu and /view/items/Dragon+F.O.F.+Cruise+Missile+I) sometimes included a period (.). When Rails 1.2 came about it introduced the respond_to method that can be used to handle requests for different types of representations for the same data:

RUBY:
  1. respond_to do |format|
  2. format.html
  3. format.js
  4. end

So /views/agents/1 will default to the HTML format and 1.xml will want the XML format.

So now the URL that looks like: /view/items/Dragon+F.O.F.+Cruise+Missile+I will want the /view/items/Dragon+F resource with the O.F.+Cruise+Missile+I format. Ooops. Bug!

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress