Routes - Search url parser

Hello, I’m trying to set my routes.rb. I have Car that belongs to
Color and Brand. I want to build a clear url searcher without visible
variables. It’s working for me this:

resources :Cars
match ‘color/:color’ => ‘cars#index’
match ‘brand/:brand’ => ‘cars#index’
match ‘brand/:brand/color/:color’ => ‘cars#index’

But I think I could do the 3 “match” in only one line. Also, posibly
there is other alternatives for do it. All advices are welcome.
Thanks!

Any help?

For give a example, the url I hope to have is something like that:

The idea is to have the same that:

But really, the user already knows that Ford is a brand and Red is a
color. I would prefer to have a url like that:

In this case I would have to parse the string in the controller. I
think would be okey this match:

  • match ‘*search’ => ‘cars#index’

Some advice? Thanks.

danimashu wrote in post #997411:

I would prefer to have a url like that:

But then what happens with:

I’d be careful of investing any particular logic behind your urls for
dealing with arguments. Do all your users catagorize things the same
way you do? Probably not.

One person I work with definitely does not prioritize attributes in the
order I do, and she is invaluable because of it.

Thanks for the answer.

But then what happens with:

In the controller would have to check that pink is a Color and
cadillac is a Brand. Problem if some day there is a Brand with name of
Color. I don’t know if it’s worth wasting time on it. The classic way
sould be the correct then:

If you have other ideas for do it you will be welcome. Bye

Daniel

On 10 May 2011 11:32, danimashu [email protected] wrote:

  • example.com/cars?color=pink&brand=cadillac
    I would advise against a strategy that could ever be ambiguous, even
    if it looks unlikely at the moment. It would likely bite you at some
    point in the future, or even worse the developer who comes hereafter,
    can you imagine what he/she would say about you when he realised the
    problem and that he would have to do some major reworking? :slight_smile:

Colin

I would advise against a strategy that could ever be ambiguous, even
if it looks unlikely at the moment. It would likely bite you at some
point in the future, or even worse the developer who comes hereafter,
can you imagine what he/she would say about you when he realised the
problem and that he would have to do some major reworking? :slight_smile:

Colin

Thanks for the advice! For the moment I will use classic way.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs