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

**URL:** <https://www.ruby-forum.com/t/hard-to-do-creating-routes-that-are-permalinks-with-context-info/177738>\
**Category:** Rails\
**Created:** [October 22, 2009, 7:54pm UTC](https://www.ruby-forum.com/t/hard-to-do-creating-routes-that-are-permalinks-with-context-info/177738 "2009-10-22T19:54:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![robb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@robb](https://www.ruby-forum.com/u/robb)\
**Post date:** [October 22, 2009, 7:54pm UTC](https://www.ruby-forum.com/t/hard-to-do-creating-routes-that-are-permalinks-with-context-info/177738/1 "2009-10-22T19:54:13Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![robb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@robb](https://www.ruby-forum.com/u/robb)\
**Post date:** [October 22, 2009, 8:25pm UTC](https://www.ruby-forum.com/t/hard-to-do-creating-routes-that-are-permalinks-with-context-info/177738/2 "2009-10-22T20:25:15Z")

</div>

On Oct 22, 10:48 am, Robb [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![robb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@robb](https://www.ruby-forum.com/u/robb)\
**Post date:** [October 22, 2009, 8:49pm UTC](https://www.ruby-forum.com/t/hard-to-do-creating-routes-that-are-permalinks-with-context-info/177738/3 "2009-10-22T20:49:16Z")

</div>

weather\_report\_url(:location =\> ‘france’, :month =\> 10, :day =\> 3)

---

<div class="post-metadata">

**Author:** ![robb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@robb](https://www.ruby-forum.com/u/robb)\
**Post date:** [October 22, 2009, 11:06pm UTC](https://www.ruby-forum.com/t/hard-to-do-creating-routes-that-are-permalinks-with-context-info/177738/4 "2009-10-22T23:06:51Z")

</div>

On Oct 22, 11:47 am, sax [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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)

---

<div class="post-metadata">

**Author:** ![robb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@robb](https://www.ruby-forum.com/u/robb)\
**Post date:** [October 23, 2009, 12:11am UTC](https://www.ruby-forum.com/t/hard-to-do-creating-routes-that-are-permalinks-with-context-info/177738/5 "2009-10-23T00:11:17Z")

</div>

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](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
