What is a “resource” in Rails?

前端 未结 6 1718
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 10:36

Dumb question but I have some lingering confusion of what, exactly, a \"resource\" is in Rails. The term is used everywhere but I get a funny feeling it might be being used

6条回答
  •  渐次进展
    2020-12-12 11:00

    A lot of people here say that resources refer to the database tables you have. It might be true sometimes but not necessarily true always. I could give you a lot of examples where you don't have a corresponding table in your database for a particular resource. Hence asssociating it with tables is rather wrong.

    I would define a resource as a route which maps to related requests. So instead of declaring separate routes for the actions you want to do you can simply declare them using a resourceful route.In Rails, a resourceful route provides a mapping between HTTP requests and URLs to controller actions.

    So say you define resources :users in config/routes.rb.
    You can now use a number of helpers to the controllers in your application like edit_user_path which returns users/edit .

提交回复
热议问题