views:

99

answers:

1

I'm setting request.format = :mobile within an ApplicationController before_filter.

before_filter :some_filter
def some_filter
   request.format = :mobile
end

I have this mapping in routes:

map.my_list '/my_list.:format', :controller => "of_no", :action => "significance"

When I do the following:

<%= link_to "My List", my_list_path %>

I get the following (ACTUAL below):

<a href="/my_list">My List</a> <!-- THIS IS THE PROBLEM -->

I want this to be (EXPECTED below):

<a href="/my_list.mobile">My List</a> <!-- THIS IS THE EXPECTED -->

However, if I do the following:

<%= link_to "My List", my_list_path(:format => "mobile") %> 

Then I get the EXPECTED result, but doing this to every "link_to" is not a viable solution.

Any idea?

Thank you

A: 

You should only need to specify the format in the helper if you want the URL to show my_list.mobile. However, if your filter doesn't use the URL to determine the format, and you're setting the format in your controller, why would you need it in the URL too? Your controller should respond to the .mobile format without it in the URL when request.format is overridden.

You could probably get away with removing the .:format part of your route definition and just rely on the request object being set.

Beerlington
The example setup was just to show the bare minimum setup for someone else to encounter the problem.I'm working with will_paginate, and it inherently (and correctly I believe) renders the pagination links with the .mobile extension (under the setup above).I was wondering if I was doing something wrong, or missing something, effectively prevented "link_to" from exhibiting the same behavior.
nosretep