logo       

Re: Catching a list of variables with a Controller: msg#00018

lang.ruby.camping.general

Subject: Re: Catching a list of variables with a Controller

This works for me:

class Filter < R '/filter/([\w/]+)'
def get tags
@tags = tags.split('/')
end
end

Then http://localhost:3301/filter/tag1/tag2/tag3 will make @tags into
['tag1', 'tag2', 'tag3']. I think this is what you want...

Roland

On Nov 14, 2006, at 3:42 PM, Boris Terzic wrote:

> Hi All,
>
> I have been learning some ruby and some Camping at the same time by
> implementing a little webapp to track expenses (one man's blog...)
> that includes the ability to tag entries with 1 or more tags.
>
> I wanted to offer the possibility to narrow the view of expenses by
> adding tags to a filter (this works) and I also wanted this filter
> to be reflected in the URL. Like so:
>
> normal URL: http://localhost:3301/
> filtered URL: http://localhost:3301/filter/tag1/tag2/tag3
>
> However, I can't get this to work since I require a variable number
> of regexp groups (like say an array) and I could not find a routing
> syntax that would allow this (something like class Filter < R '/
> filter/(\w/)*' ).
>
> I currently use a route which looks like:
>
> class Filter < R '/filter', '/filter/(.+)'
>
> And I represent the N tags as a string where tags are comma-
> separated. It works but purty, it isn't.
>
> Suggestions? Or am I bonkers?
>
> Thanks.
>
> --
> Boris


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise