Is there a way to have a route allow an :id
or a nil
?
For example:
match 'product_specs/:id' => 'home#product_specs',
:as => :product_specs,
:via => :get
takes the id
as a param. But I'd also like to pass an empty param like this product_specs_path()
so that I can also have the option of loading all my records.
Is there a routes match that can achieve this?
perhaps if you use the optional parameter as
# Routes
match 'product_specs/(:id)' => 'home#product_specs'
# Controller
def product_specs
if params[:id].nil?
product_specs = ProductSpecs.all()
else
product_specs = ProductSpecs.find(params[:id])
end
Would something like that work?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With