#302 √ resolved
GMFlash

[PATCH] Remove nil items from params hash when generating routes

Reported by GMFlash | May 7th, 2008 @ 01:28 AM

Currently when generating routes there is no easy way to remove query params. Any param assigned to nil results in a blank query param.

irb(main):001:0> Merb::Router.generate(:controller => 'cont', :action => 'act', :color => 'red', :size => nil)

=> "/cont/act?color=red&size="

----------

This patch updates the #generate method in the router to remove params that are assigned a nil value. It follows the same convention as Rails.

irb(main):001:0> Merb::Router.generate(:controller => 'cont', :action => 'act', :color => 'red', :size => nil)

=> "/cont/act?color=red"

----------

Now you are able to do something like: url(:date => (@date == Date.today) ? nil : @date))

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket