Hard to do: Creating routes that are permalinks with context info

Simple permalinks, yes, like:

/weather/report/10/3

But I do not see how to create permalinks for large collections of
documents, like:

/france/weather/report/10/3
/europe/weather/report/10/3

There’s one big difference between the first and second example: In
the first, all the parameters would be attributes of the one
ActiveRecord object (the weather report from 10/3.)

But in the second examples, information from two sources is pulled
from: the AR object as above, plus a sort of application context —
the user is focussing on France or Europe. I haven’t figured out how
to generate these kinds of URLs yet. Anyone know how? Here’s what I
have so far:

map.weather_report ‘/:location/weather/report/:month/:day’ …

This nicely (1) sets an @location variable in the app so that the
entire interface is tailored for the user, and (2) instantiates
the :month/:day weather report, filtered by @location.

But my problem: I don’t see how to use weather_report_path to
generate this URL. Given a report object, and @location, I’ve tried
variations of:

weather_report_path(report, @location)

…without success.

Any ideas?
Thanks!

On Oct 22, 10:48 am, Robb [email protected] wrote:

Simple permalinks, yes, like:

/weather/report/10/3

But I do not see how to create permalinks for large collections of
documents, like:

/france/weather/report/10/3
/europe/weather/report/10/3

Hmm; it looks like one solution might be to use nested resources,
which would unfortunately require a longer url like this:

/locations/france/weather/report/10/3

weather_report_url(:location => ‘france’, :month => 10, :day => 3)

On Oct 22, 11:47 am, sax [email protected] wrote:

weather_report_url(:location => ‘france’, :month => 10, :day => 3)

Ummhmm, I can grab out the attributes of my Report object. And I guess
I can use that with link_to in a template:

link_to(‘the report’, weather_report_url(:location => @loc, :month
=> r.month, :day => r.day))

…I was hoping to get to something more like:

link_to(‘the report’, @loc, r)

On Oct 22, 2009, at 5:04 PM, Robb wrote:

link_to(‘the report’, @loc, r)

You’ll never get it quite that simple unless you write your own helper.

module MyHelper
def weather_link_to(text, location, report, options={})
link_to(text, weather_report_path(:location => location,
:month => report.month,
:day => report.day),
options)
end
end

<%= weather_link_to(‘the report’, @loc, r) %>

-Rob

Rob B. http://agileconsultingllc.com
[email protected]