PascalTurbo
PascalTurbo

Reputation: 2363

Use a namespace only as param

At the moment my routes are looking like this:

search_index GET   /search(.:format)     search#index

But I want to get routes like these:

search_index GET   /topic1/search(.:format)    search#index
search_index GET   /topic2/search(.:format)    search#index

As you can see, I don't want to introduce namespaces. The "topic" part of the url shall only be transported as a param.

Upvotes: 1

Views: 323

Answers (1)

Filip Bartuzi
Filip Bartuzi

Reputation: 5931

in your routes.rb append:

match '/:topic_name/search' => 'search#show', via: :get

this will add topic_name to your params, accessible in controller - params[:topic_name]

Upvotes: 4

Related Questions