如何从路由(URL)中删除控制器名称?

时间:2019-05-28 07:01:31

标签: ruby-on-rails ruby routes

如何从路由(URL)中删除控制器名称?

Example :

Existing Url: https://localhost:3000/home/contact_us

I want this URL https://localhost:3000/contact_us

那我该怎么办?

  

Route.rb

     

将“ home / contact_us”获取为:“ home#contact_us”,例如::contact_us

2 个答案:

答案 0 :(得分:3)

尝试

get "contact_us", to: "home#contact_us", as: :contact_us

答案 1 :(得分:0)

get "contact_us", to: "home#contact_us"

as: :contact_us # not required