how to set up and use a Rails routes prefix

后端 未结 7 913
北海茫月
北海茫月 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:10

    It let's you use shortcuts such as new_article_path or new_article_url in your controllers and views. These come in very handy when doing things like redirecting users to a specific page or generating dynamic links.

    You can change the prefix by adding the as: option in your routes.rb file. For example:

    GET '/new', to: 'articles#new', as: 'my_new_article`
    

    This would change the prefix to my_new_article.

提交回复
热议问题