Custom url in ruby on rails

后端 未结 2 492
醉话见心
醉话见心 2021-01-21 01:29


I know rails uses the controller action style urls like www.myapp.com/home/index for example
I would like to have a url like this on my rails app,

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 02:15

    you just need to make a routing rule to match that url in this case it will be something like

    match 'my_page_here' => 'your_controller#your_action'
    

    your controller and action will specify the behavior of that page

    so you could do

    match 'my_page_here' => 'home#index'
    

    or

    get 'my_page_here', :to => 'home#index'
    

    as suggested in other responses.

    for index action in home controller if you have such a controller

    see http://guides.rubyonrails.org/routing.html for more details

    also see Ruby on Rails Routes - difference between get and match

提交回复
热议问题