I've just setup my router to route category resources with :id
and :alias
:
resources :categories, param: 'id/:alias'
Now, my routes are setup correctly, for example 'show' becomes:
category GET /categories/:id/:alias(.:format) categories#show
The to_param
method on Category
:
def to_param
{ id: id, alias: name.parameterize }
end
When using link_to category
, it throws this error:
- No route matches {:controller=>"categories", :action=>"show", :id=>#< Category id: 2, name: "Buiten", description: "", ancestry: nil, created_at: "2014-04-25 16:13:11", updated_at: "2014-04-25 16:13:11">, :alias=>nil, :format=>nil} missing required keys: [:alias]
I want to use links like this:
= link_to category
I do NOT want to use links like this:
= link_to category_path( { id: category.id, alias: category.name.parameterize } )
Is this possible?
app.category_path(id: 2, alias: "asas")
did it throw error ? – Rajarshi Dasnil
that's why it was throwing error – Rajarshi Dasapp.category_path(id: 2, alias: nil)
now you see it will throw error – Rajarshi Das:alias=>nil, :format=>nil}
– Rajarshi Dasto_param
and send it as a parameter of query like/categories/2?alias=anything
– Rajarshi Das