fail_lord fail_lord - 10 months ago 50
Ruby Question

Rails resources and custom urls

I have a model Posts with titles, categories, months, and tags. When I filter these using a parameter, how do I construct the routes to look like this:





Currently, the URL looks like
. I understand the solution has something to do with resources buts it's very confusing. Thanks.


This won't be a best practice answer, but it looks like you've already went the other way, so

In you routes.rb create a route:

get 'categories', to: 'posts#categories', as: 'show_categories'

In your Posts controller you can create a new action called categories:

def categories
  @posts = Post.where ... (pick your catgory or month using params)

Create a new categories.html.erb view in your Posts view folder, and there you go.