Rails服务实现:路由、表示格式与控制器设计
1. 路由文件 routes.rb 的实现
在Rails应用中,我们需要将数据集分割到不同的控制器中,并且每个控制器会进一步将数据集划分为一种或两种资源。同时,Rails也会为我们决定URI的格式,但我们可以对部分默认设置进行调整。
为了将路径片段(如 bookmarks/ )映射到控制器类(如 BookmarksController ),我们需要使用 routes.rb 文件。以下是一个 routes.rb 文件的示例:
# service/config/routes.rb
ActionController::Routing::Routes.draw do |map|
base = '/v1'
## The first controller I define is the UsersController. The call to
## map.resources sets it up so that all HTTP requests to /v1/users
## or /v1/users/{username} are routed to the UsersController class.
# /v1/users => UsersController
map.resources :users, :path_prefix => base
## Now I'm going to defi
超级会员免费看
订阅专栏 解锁全文
8

被折叠的 条评论
为什么被折叠?



