[LRUG] REST and Associations

Eleanor eleanor at goth-chic.org
Thu Mar 1 17:04:19 PST 2007


On 27 Feb 2007, at 15:57, Piers Cawley wrote:
> The problem I have with the current routing approach is that you have
> to know too much to generate them. If I've got things set up so that
> (for instance) comments are nested within articles, then I don't want
> to have to call 'comment_url comment.article, comment'. And, when my
> default article URL is of the form:
>
>    /articles/2006/06/01/article-title
>
> I want to generate that with a call to 'article_url article' rather
> than the current mess:
>
>     url_for :year => article.year, :month => article.month,
>             :mday => article.day, :slug => article.slug
>
> Maybe if #to_param. I'm currently toying with implementing a
> #to_url_hash method on my models, which will generate an appropriate
> hash to pass to url_for... or maybe extending routing so one could
> specify:
>
>    /articles/:article[year]/:article[month]/:article[day]/:article 
> [slug]

I was discussing the current routing mechanism with my colleague  
Romek the other day. The Rails approach to routing is fine for simple  
cases, but as the REST architecture encourages arbitrary resource  
nesting Rails could really do with something in the way of a classic  
production or inference system - maybe even a Prolog-style routing  
DSL. If only I had the time to investigate further..!


Ellie

Eleanor McHugh
Games With Brains
----
raise ArgumentError unless @reality.responds_to? :reason




More information about the Chat mailing list