Robb
2009-Oct-22 17:48 UTC
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!
Robb
2009-Oct-22 18:23 UTC
Re: Hard to do: Creating routes that are permalinks with context info.
On Oct 22, 10:48 am, Robb <robb.shec...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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/3Hmm; 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
sax
2009-Oct-22 18:47 UTC
Re: Hard to do: Creating routes that are permalinks with context info.
weather_report_url(:location => ''france'', :month => 10, :day => 3) On Oct 22, 11:23 am, Robb <robb.shec...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Oct 22, 10:48 am, Robb <robb.shec...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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
Robb
2009-Oct-22 21:04 UTC
Re: Hard to do: Creating routes that are permalinks with context info.
On Oct 22, 11:47 am, sax <s...-c5KP9hz/kbxwMgcQ4+lbG0B+6BGkLq7r@public.gmane.org> 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)
Rob Biedenharn
2009-Oct-22 22:08 UTC
Re: Hard to do: Creating routes that are permalinks with context info.
On Oct 22, 2009, at 5:04 PM, Robb wrote:> On Oct 22, 11:47 am, sax <s...-c5KP9hz/kbxwMgcQ4+lbG0B+6BGkLq7r@public.gmane.org> 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)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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org