0

I have Products page that use the ugly param to handle sorting.

products_path(sort: "asc")

# resulting in
/products?sort=asc

I'm trying to make the URL looks like /products/asc. So I'm playing with the routes:

# routes.rb
get "/products/:sort", to: "products#index", as: "products_path"

Now, going to /products/asc works perfectly fine.

But products_path(sort: "asc") still generate /products?sort=asc.

Is there a way to make it generate the pretty URL?

Thanks

[EDIT and ANSWER]

I typo the as:. Should be:

# routes.rb
get "/products/:sort", to: "products#index", as: "products"

2 Answers 2

1

Move get "/products/:sort", to: "products#index", as: "products" above resources :projects in routes.rb

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks for the reply. Actually I made mistake, it supposed to be as: "products" instead of as: "products_path"
0

I typo the as:. Should be:

# routes.rb
get "/products/:sort", to: "products#index", as: "products"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.