Flowdock

Good notes posted by matbrown

RSS feed
November 11, 2008
4 thanks

:use_route to force named routes in url_for

If you are using a plugin or library that calls url_for internally, you can force it to use a particular named route with the :use_route key. For instance, calling:

url_for(:controller => 'posts', :action => 'view', :id => post, :use_route => :special_post)

will have the same effect as:

special_post_url(post)

Naturally, this is much more verbose if you’re calling it directly, but can be a lifesaver if url_for is being called inside another method (e.g. will_paginate).