Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named Routes and Sexy URLs #46

Closed
omargallob opened this issue Mar 2, 2011 · 2 comments
Closed

Named Routes and Sexy URLs #46

omargallob opened this issue Mar 2, 2011 · 2 comments

Comments

@omargallob
Copy link

hi there,

i want kaminari to use the following route :

match "/:category(/page/:page)" => "viewer#index", :as => "category_index"

instead of going to the old route

/viewer/index?category=fiction&page=2

would i have to modiify the kaminari views? cant find any posts or comments from any1 with relation to this

@joshuabowers
Copy link

Hi omargallob:

In case you have not stumbled across an answer to this elsewhere, I believe I can confirm that. I have defined in my routes file a named route something like the following:

resources :parts do
  collection do
    get 'search/:search(/page/:page)' => 'parts#index', :as => :search
  end
end

With a route like that in place, links generated with link_to will indeed transform a params hash with keys like :search and :page to a cleaner form. E.g.:

search_parts_path(:search => "foobar", :page => 2)
 => '/parts/search/foobar/page/2'

So, your example should work. You can actually get really complex with this stuff. My actual route matches the following pattern:

'(search/:search)(/sort/:sort(/:direction))(/page/:page)'

Which kaminari seems to have absolutely no issues using.

@omargallob
Copy link
Author

Sorted it out, i had a "get" at the top of the routes.rb which was messing up the sexy urls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants