【问题标题】:Rails:what's the different between 'Get' and 'Resources' ?Rails:“获取”和“资源”有什么不同?
【发布时间】:2015-07-15 19:07:23
【问题描述】:

试图在铁轨上创建路线,但我只是不明白其中的不同 在“获取”和“资源”之间。

谢谢你

【问题讨论】:

    标签: ruby-on-rails controller routes


    【解决方案1】:

    当您使用 get 动词时,您只会创建 1 条路由,该路由被创建为 get 以匹配您匹配的路由。 get /photos 用动词 get 创建路由 /photos

    当您使用resources 时,它会创建 7 条路由,例如: resources :photos 会生成

    GET     /photos     photos#index    display a list of all photos
    GET     /photos/new     photos#new  return an HTML form for creating a new photo
    POST    /photos     photos#create   create a new photo
    GET     /photos/:id     photos#show     display a specific photo
    GET     /photos/:id/edit    photos#edit     return an HTML form for editing a photo
    PATCH/PUT   /photos/:id     photos#update   update a specific photo
    DELETE  /photos/:id photos#destroy  delete a specific photo
    

    也检查一下

    Rails routing

    【讨论】:

      猜你喜欢
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多