how to set up and use a Rails routes prefix

后端 未结 7 916
北海茫月
北海茫月 2021-02-05 07:39

When running rake routes I see:

 Prefix   Verb   URI Pattern                                       Controller#Action
 articles  GET    /articles(.:format)               


        
7条回答
  •  南方客
    南方客 (楼主)
    2021-02-05 08:06

    You can do something like this:

    resources :articles do
     collection do
          get  "new"  => "articles#new",  :as => 'new_document'
     end
    end
    

    and you can use it:

    link_to "New foo", new_document_path 
    

    or

    link_to "New foo", new_document_url
    

    url prints the absolute url (http://server.com/controller/action) meanwhile path prints the relative url (/controller/action).

提交回复
热议问题