For you Streamlined users out there, here’s an easy way to include named routes in your Streamlined addition modules. Previously, you had to hard code the URLs like so:
module OrderAdditions
def name_link
link_to user.name, "/users/show/#{user.id}"
end
end
Order.class_eval do
include OrderAdditions
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
end
Streamlined.ui_for(Order) do
list_columns :name_link
end
By including Rails 2’s new ActionController::UrlWriter module, you can access any named or RESTful routes you’ve defined in routes.rb:
module OrderAdditions
def name_link
link_to user.name, user_url(user.id)
end
end
Order.class_eval do
...
include ActionController::UrlWriter
default_url_options[:host] = APP_HOST
end
It would be nice for this to get baked into Streamlined somehow so UrlWriter automatically gets included, but until that happens this is a good way to get rid of those pesky hard-coded URLs.