If you want to keep the index method foo_bars and the separate bars route:
Create your own route in routes.rb :
get 'bars' => 'bars#index', as: :bars
Set up your index method in your bars controller as described in your link, or simply:
def index if params[:foo_id] @bars = Foo.find(params[:foo_id]).bars else @bars = Bar.all end end
Then create the bars browsing directory (if you don't have one) and index.html.erb .
If you do not want to use the foo_bars index foo_bars :
Create your own route in routes.rb :
get 'bars' => 'bars#index', as: :bars
Edit existing routes to exclude the nested index:
resources :foos do resources :bars, except: :index end
Then the bars controller could be as follows:
def index @bars = Bar.all end
Then create the bars browsing directory (if you don't have one) and index.html.erb .
source share