Add example for friendly URLs with concern in README
Thanks to @IngusSkaistkalns for his suggestion. closes #588
This commit is contained in:
parent
5f9b7956c5
commit
5d4eba8589
|
@ -271,6 +271,14 @@ Because of the +page+ parameter and Rails 3 routing, you can easily generate SEO
|
||||||
get 'page/:page', :action => :index, :on => :collection
|
get 'page/:page', :action => :index, :on => :collection
|
||||||
end
|
end
|
||||||
|
|
||||||
|
If you are using Rails 4 or later, you can simplify route definitions by using `concern`:
|
||||||
|
|
||||||
|
concern :paginatable do
|
||||||
|
get '(page/:page)', :action => :index, :on => :collection, :as => ''
|
||||||
|
end
|
||||||
|
|
||||||
|
resources :my_resources, :concerns => :paginatable
|
||||||
|
|
||||||
This will create URLs like <tt>/my_resources/page/33</tt> instead of <tt>/my_resources?page=33</tt>. This is now a friendly URL, but it also has other added benefits...
|
This will create URLs like <tt>/my_resources/page/33</tt> instead of <tt>/my_resources?page=33</tt>. This is now a friendly URL, but it also has other added benefits...
|
||||||
|
|
||||||
Because the +page+ parameter is now a URL segment, we can leverage on Rails page caching[http://guides.rubyonrails.org/caching_with_rails.html#page-caching]!
|
Because the +page+ parameter is now a URL segment, we can leverage on Rails page caching[http://guides.rubyonrails.org/caching_with_rails.html#page-caching]!
|
||||||
|
|
Loading…
Reference in New Issue