Reputation: 15002
I want to replace root to welcome controller,
But if I use the url http://localhost:3000/welcome/portfolio
The action 'welcome' could not be found for WelcomeController
How to not affect original controller with the routes rule match '/:action(/:id)', :controller => "welcome",via: [:get, :post]
Prefix Verb URI Pattern Controller#Action
root GET / welcome#index
GET|POST /:action(/:id)(.:format) welcome#:action
portfolio_welcome_index GET /welcome/portfolio(.:format) welcome#portfolio
welcome_index GET /welcome(.:format) welcome#index
POST /welcome(.:format) welcome#create
new_welcome GET /welcome/new(.:format) welcome#new
edit_welcome GET /welcome/:id/edit(.:format) welcome#edit
welcome GET /welcome/:id(.:format) welcome#show
PATCH /welcome/:id(.:format) welcome#update
PUT /welcome/:id(.:format) welcome#update
DELETE /welcome/:id(.:format) welcome#destroy
root :to => "welcome#index"
match '/:action(/:id)', :controller => "welcome",via: [:get, :post]
resources :welcome do
collection do
get 'portfolio'
end
end
Upvotes: 0
Views: 31
Reputation: 2165
it happens because /:action(/:id)
handel each path with format /something/some_id
and even /something
so you could put it to the end in routes file:
resources :welcome do
collection do
get 'portfolio'
end
end
match '/:action(/:id)', :controller => "welcome",via: [:get, :post]
root :to => "welcome#index"
in this case request to /welcome/portfolio
will be handled with resources
definition before going to your /:action(/:id)
definition.
Upvotes: 1