1

Using the rails script, I have generated a five column table (ID, title, content, created_at, updated_at) and its relevant views and controllers using the following command:

rails generate scaffold Input title:string content:text

It also created a few new routes for the creation, the reading, the updating and the deletion of database entries:

 inputs GET    /inputs(.:format)           inputs#index
                 POST   /inputs(.:format)           inputs#create
       new_input GET    /inputs/new(.:format)       inputs#new
      edit_input GET    /inputs/:id/edit(.:format)  inputs#edit
           input GET    /inputs/:id(.:format)       inputs#show
                 PUT    /inputs/:id(.:format)       inputs#update
                 DELETE /inputs/:id(.:format)       inputs#destroy

But where are these routes stored? They're not in rails' 'routes.rb' file!

4

2 回答 2

1

打开你的config/routes.rb文件。您会找到一个条目resources :inputs

这负责使用您在上面看到的有意义的路径助手创建这些 RESTful 路由。

默认情况下, Aresource为模型添加七个操作 - neweditcreateupdatedestroyindexshow。所有这些都由通用 URI 和 HTTP 动词触发(GET, POST, PUT, DELETE)

于 2013-05-14T14:36:22.283 回答
0

http://guides.rubyonrails.org/routing.html

进一步来说

resources :photos 在您的应用程序中创建七个不同的路由,所有路由都映射到 Photos 控制器:

于 2013-05-14T14:37:15.293 回答