Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ransack and nested routing

I have the following type of resource routing:

resources :cities do
  resources :restaurants
end

Which gives rise to the following type of routing:

/restaurants/:city_id/

In my restaurant index controller I have the usual ransack code, however when I click the search button I am redirected to /restaurants instead of /restaurants/:city_id.

How can I tweak ransack so when the search form is submitted it redirects to the url /restaurants/:city_id instead of /restaurants.

Thanks!

like image 460
Jamal Khan Avatar asked Feb 12 '26 01:02

Jamal Khan


1 Answers

You can set manuel url

<%= search_form_for @q, url: city_restaurants_path(params[:city_id]) do |f| %>
like image 98
Muhammet Avatar answered Feb 14 '26 17:02

Muhammet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!