我想将root替换为welcome controller,
但是,如果我使用网址http://localhost:3000/welcome/portfolio
行动'欢迎'找不到WelcomeController
如何使用路线规则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
答案 0 :(得分:1)
/:action(/:id)
使用格式为/something/some_id
甚至/something
的每个路径,因此您可以将其放在路径文件的末尾:
resources :welcome do
collection do
get 'portfolio'
end
end
match '/:action(/:id)', :controller => "welcome",via: [:get, :post]
root :to => "welcome#index"
在这种情况下,在转到/welcome/portfolio
定义之前,将resources
定义处理/:action(/:id)
的请求。