routing - Rails RESTful URL's: All Posts under certain Category -


currently use posts#index action show posts or filter'em category in case specified:

postscontroller:

def index   @posts = post.all(:order => "created_at desc")   @posts = @posts.by_category(params[:category_id]) #custom named_scope end 

routes:

map.connect '/post/by_category/:category_id', :controller => :posts, :action => :index map.resources :users 

so /posts return all posts, , /posts/by_category/1 return all posts under category 1

i wonder if there way of doing more restful, , maybe pretty url_paths.

i've read guides (using latest 2.3 rails branch) neither nested routes nor collections seemed appropiate case. :)

resources :posts resources :categories |categories|   categories.resources :posts end 

your urls then:

/posts - posts

/posts/:id -certain post

/categories - categories

/categories/:id - category

/categories/:id/posts - posts within category.


Comments