Hello all.
I have what I think is a pretty common dilemma with Rails routing, and I
haven’t been able to find or come up with a clean/DRY solution.
I have a home controller that is used for displaying real estate
information. I want to be able to show this information on different
platforms in different ways: desktop and mobile. I have seen similar
topics for displaying custom iphone interfaces, but that usually
involved using subdomains, which is not an option for me.
First, here is the relevant routing:
map.resource :home map.with_options :controller => 'home' do |r| r.property '/property/:listing_id', :action => 'show' r.property_details '/property/:listing_id/details', :action => 'details' r.search '/search', :action => 'search', :conditions => { :method => :post } end
So what I want to do is have urls that looks like this:
/desktop/property/1 -or-
/mobile/property/2/details
I know that I can add a route like this:
r.property '/:platform/property/:listing_id', :action=>'show', :target_platform => /(desktop|mobile)/i
The problem with this is that it isn’t DRY, as every named route would
now need the /:platform/ prefix added to it. Additionally, every URL I
want to call would explicitly need to specify the platform, like so
(again not DRY):
property_path(:listing => 1, :platform => ‘desktop’)
Finally, I know you can add custom respond_to with Rails 2.0 (e.g
request.format = :iphone), but I want to allow the user to select the
format, not purely based on detection.
Anyway, if you are still reading this, thank you. I’d greatly
appreciate any sort of help. I have seen similar discussions
surrounding internationalization (e.g. /en/home/ vs /fr/home).
Thanks again.