4.资源路由的示例

PrefixHTTP VerbPathController#ActionUsed for
articlesGET/photosphotos#indexdisplay a list of all photos
new_articleGET/photos/newphotos#newreturn an HTML form for creating a new photo
POST/photosphotos#createcreate a new photo
articleGET/photos/:idphotos#showdisplay a specific photo
edit_articleGET/photos/:id/editphotos#editreturn an HTML form for editing a photo
PATCH/PUT/photos/:idphotos#updateupdate a specific photo
DELETE/photos/:idphotos#destroydelete a specific photo

资源路由设置了URL和path帮助器方法,我们可以使用这些方法来防止代码依赖于特定的路由配置。上面“prefix”列中的值加上这些助手的后缀_url_path形成这些助手的名称。例如,给定文章时,article_path助手将返回 "/articles/#{article.id}"

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/ruby/rubyonrails/3381.html

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注