ExceptionLogger plugin and Edge (2.0 RC)
- Posted by alex on October 31st, 2007 filed in work
- Comment now »
I love the ExceptionLogger plugin. And I love developing on Rails Edge (which is currently between 2.0 PR and 2.0 RC). I recently ran into a small headache when trying to get ExceptionLogger to work with a standard EdgeRails setup, and there seemed to be things missing from their README.
Install RedCloth:
|
|
sudo gem install redcloth -y |
Modify your routes (it seems to me that this was unecessary before the PR):
|
|
map.connect ‘logged_exceptions/:action/:id‘, :controller => ‘logged_exceptions‘ |
Get it working with will_paginate. In logged_exceptions_controller, change this:
34 35 |
@exception_pages, @exceptions = paginate :logged_exceptions, :order => ‘created_at desc‘, :per_page => 30, :conditions => conditions.empty? ? nil : parameters.unshift(conditions * ‘ and ‘) |
to this:
34 35 |
@exceptions = LoggedException.paginate :order => ‘created_at desc‘, :per_page => 30, :page => (params[:page] || 1), :conditions => conditions.empty? ? nil : parameters.unshift(conditions * ‘ and ‘) |
Finally, in the views/logged_exceptions folder in the plugin, there is a partial called _exceptions.rhtml. Replace the if conditionals that reference the old pagination objects with this:
4 … 50 |
<%= will_paginate @exceptions %> … <%= will_paginate @exceptions %> |
Enjoy!
Query Key Translation Ruby on Rails Plugin (Rails Routing pt. 3)
- Posted by alex on June 20th, 2007 filed in work, ruby on rails
- Comment now »
Translate query keys in Ruby on Rails with this Plugin.
After getting approval from the big boss, I’m now publishing my first rails plugin. This is a plugin I’ve previously talked about developing here and here.
The plugin extends Ruby on Rails route recognition/dispatching to allow controllers to refer to parameters passed in on the query portion of the URL with translated names. Additionally, URL generation via url_for and its helper methods like link_to have been extended to generate links with translated query keys. A single configuration within routes.rb allows this.
Note the ‘translates’ key/value pair added to each route definition.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
ActionController::Routing::Routes.draw do |map| # Our old application accepted URLs like this. # We refer to the parameters as :page and :sort # in our new app, the old URLs will have ‘p’ and ’s’ map.connect ‘legacy_action.jsp‘, :controller => ‘legacy‘, :action => ‘action‘, :translates => {:p => :page} # we want urls like: http://example.com/search?q=Pizza+Hut&l=en map.connect ‘search‘, :controller => ‘search‘, :action => ‘search‘, :translates => {:q => :search_query, :l => :language} end |
Long Hours
- Posted by alex on June 19th, 2007 filed in work
- Comment now »
Starting to feel the effects of 55 hour weeks… I feel bad for some colleagues who are working even longer hours (they have children at home waiting for them!).
Virtual Machines
- Posted by alex on June 17th, 2007 filed in work
- Comment now »
The release of Parallels 3.0 has been a day that I’ve been waiting for. Since the first time I was exposed to virtualization of operating systems, I’ve hoped that one day I would be able to run Windows as a virtual machine, and still be able to play all the games I love. Half-Life 2 is close to playable at 10-20 FPS in a Parallels virtual machine running on my Macbook Pro. Quake 4 looks like it runs even better. I’ll post a video if I ever end up getting my mac pro (and if I get enough time to actually do anything besides work).
The downside of living on the bleeding edge
- Posted by alex on June 17th, 2007 filed in work
- Comment now »
Digging up old work
- Posted by alex on June 5th, 2007 filed in ruby on rails
- Comment now »
I spent some free time this evening looking at some old rails projects that I’ve worked on. One in particular has a lot of potential, and I’ll be spending some time refactoring it. During the Spring of my senior year, I was contracted along with 3 other students to work on a calendar web application that was built specifically to help administrators at a retail store create work schedules. The code needs to be brought up to date, since it was written in the pre 1.1 era of Rails, and some of the features specific to the client we developed it for need to be removed as well in order to make the application more accessible and general purpose. Once its up and running, I’ll be putting together a gallery of running applications I’ve worked on as a little portfolio. If there is significant interest in the calendar app, I’ll build it out as a fully functional web application for public use.
Translating query parameter keys in Rails
- Posted by alex on June 5th, 2007 filed in work, ruby on rails
- 1 Comment »
UPDATE:
I have made the plugin publicly available.
Building beautiful URLs in Ruby on Rails is easy. One of the major reasons we chose Ruby on Rails as our development platform was because it gave us a lot of freedom in creating search engine friendly URLs for our search engine results pages (SERPs). Building nice paths that suggest a file-directory like structure to our site will help search engines like Google figure out how pages are related and how best to index and serve the pages. A url from our J2EE site looks like this:
http://www.yellowpages.com/sp/yellowpages/ypresults.jsp?refined_category=Pizza&DCSext.catReg=TopCat&q=pizza&rType=headingtext&id=1&p=1&prop22=TopCat&DCSext.CatValRegion=TopCat&referrer=2&pageName=catRes_pg&WT.cg_n=catRes_pg&v=3&t=0&st=CA&s=2&ci=Pasadena&_requestid=768376
This is confusing to search engines and users alike. Ruby on Rails enables us to easily build a routing configuration file that helps us build category search URLs that look like this:
http://www.yellowpages.com/Pasadena-CA/Pizza
Unfortunately, beyond the simple use case of one word search strings, things begin to get complicated. When building a search web application, it is important to keep the exact formatting of the user entered search terms for various reasons, and shoving search terms that contain punctuation into the path of a URL makes for really ugly looking URLs. Additionally, we don’t want multiple URLs pointing to the same content, so normalizing user entered search strings becomes necessary. Since our search engine strips out punctuation anyway, we can do the punctuation stripping at the application level in order to build canonical strings representing the content of a SERP.
#Not only are these URLs ugly, they are two different URL paths #pointing to the same content which makes Google a bit suspicious. http://www.yellowpages.com/Pasadena-CA/L+%26+L+BBQ http://www.yellowpages.com/Pasadena-CA/L%26L+BBQ #URL paths should have no punctuation (like in a file directory) #and should have normalized search terms. We should #maintain the originally entered search term in some other way. #The SERP should still display if the original search terms #are omitted. We will send URLs without original search terms #to google to be indexed. http://www.yellowpages.com/Pasadena-CA/L-L-BBQ http://www.yellowpages.com/Pasadena-CA/L-L-BBQ?q=L+%26+L+BBQ http://www.yellowpages.com/Pasadena-CA/L-L-BBQ?q=L%26L+BBQ #Note: Building URLs that are search engine friendly is a lot #different than building URLs that are programmer friendly. #When exposing a REST based local search API, we would use #RESTful routes to build URLs like this: http://api.yellowpages.com/locations/Pasadena+CA/listings/search.xml?name=L+%26+L+BBQ
The above solution gives us nice URLs, with a single URL Path pointing to the content, and still allows us to display feedback to the user about their entered search terms while maintaining a stateless application flow from search box to SERP.
Get the plugin.
Rails Routing pt. 2
- Posted by alex on April 4th, 2007 filed in work, ruby on rails
- 4 Comments »
It turned out that the ‘arbitrary constraint’ was a bug afterall. The bug was fixed in release 1.2.3, and has made my life much easier. Since the release, I’ve developed a plugin at Yellowpages.com that allows route generation via query parameters and translation of query parameter keys so that we can use short one character keys like ‘?t=pizza’ instead of ‘?search_terms=pizza’. The configuration is handled in routes.rb, and is as simple as adding a hash :translates => {:t => ’search_terms’} to the route you want to translate. This way, the URL will contain the ‘t’ string in the query parameters, and the application can refer to the parameter as params[:search_terms].
I will be posting the code shortly.
UPDATE:
I have made the plugin publicly available.
Rails routing: Query parameters
- Posted by alex on March 5th, 2007 filed in work, ruby on rails
- Comment now »
While working on the next generation site at Yellowpages.com (being built on Ruby on Rails), I’ve had numerous opportunities to look into the innerworkings of the framework. One major point of frustration for me so far has been what seems like an arbitrary constraint of the framework in the URL Routing code. Jamis Buck has done an outstanding job of explaining a lot of the “magic” behind routing, but he has glossed over the important subject of adding query parameters to the URL. While most simple applications built in rails can get away with storing lots of state in the session and the URL path, we can’t do that at Yellowpages.com. One of the goals of our next gen site effort is to make our application as stateless as possible. It might be naïve to assume that we can accomplish this goal, but so far, the constraint has made us more creative, and our application more responsive to high load. Because of the stateless nature of our current prototypes, storing application state in the URL path has become too difficult, and we will be instead storing a few key pieces of data in the URL via query parameters. Unfortunately, in Rails, if you are using keys for your query parameters that have previously been used as significant (path based) keys on your other routes, Rails will happily omit the query parameter key/value pair altogether. I think (after looking at the code) that this was a design consideration and not a bug, and I’ve probed the Rails mailing list, and Jamis himself for an answer as to why this is necessary. Hopefully any workarounds that I post here later will solve the problem elegantly, or Jamis/the rails community will convince me that its not a problem at all.
Car Blogging
- Posted by alex on February 17th, 2007 filed in gadgets
- Comment now »
![]()
Admittedly, I’m a little behind the times for a self proclaimed gadget freak. I’ve always been in love with electronic doodads, but my reach no longer exceeds my grasp. I recently purchased a Macbook Pro (after being without any Apple computers for an agonizing 8 month span), and I recently hooked it up to my Blackberry Pearl. T-Mobile currently only offers EDGE data plans in my area, so the browsing speeds in the car were slightly reminiscent of our original 56k modem in our first Windows 98 PC, but the experience proved that there is enough connectivity through a cell phone to get work done on the internet while on the move. Maybe this means I can start taking the train/bus to work. I’d be able to connect to the net for light browsing, or working, and I wouldn’t be so drained by the commute. This opens up new possibilities for living arrangements.
I guess I’ll have to investigate further. For now, I’m just enjoying the benefits of owning a Mac again.