Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Routing: how to separate a token from surrounding static segments

I'm having one of those bizarre "this used to work and then it stopped working" issues.

In my routes file I have

    controller :questions do
        match 'q/:topic-questions/:tag' => :search
    end

So a URL of format q/java-questions/performance would route to the search action with params[:topic] = java and params[:tag] = performance

This used to work, but now I get a route not found error. If I switch to

match 'q/(:topic)-questions/:tag' => :search

it finds the route again, but I don't want topic to be an optional parameter. I think this implies that it's having trouble separating out :topic-questions into a token and then a static string. If there another way to neatly separate out the token, other then putting it in ()?

Note - the reason why topic cannot be an optional parameter, is that optional parameters are not included in the cache keys when doing action caching.

like image 609
cailinanne Avatar asked Feb 22 '23 10:02

cailinanne


1 Answers

what about:

controller :questions do
    match 'q/:topic-:modifier/:tag' => :search
end

then you would have three parameters

params[:topic]
params[:modifier]
params[:tag]

and you could then ignore the params[:modifier] one.

like image 81
sorens Avatar answered Mar 05 '23 18:03

sorens