I have a super basic Rails app with a couple of forms. I have 5 controllers, and each of them have only 1 index view, and possibly more in the future. What I want to achieve is, that when I type in browser http://example.com/discover Rails automatically loads discover controller index method, and if I want http://example.com/discover/city it loads discover controller and “city” method. So, I have my routes.rb containing this at the moment:
root :to => "home#index"
match '/discover/' => 'discover#index'
match '/start/' => 'start#index'
match '/blog/' => 'blog#index'
match '/help/' => 'help#index'
match '/about/' => 'about#index'
I am looking for a way to write a generic route rule, that would always look for index method using the controller, and for a specific methods in the controller if I add a secondary argument to the link.
This seems so easy, but I cannot find a straight forward way of doing this.
Use this wildcarded route:
Be aware with this, it can let you access stuff you don’t want to be accessible.