Rails 3 API与RABL

Pau*_*aul 4 api ruby-on-rails-3 rabl

我正在尝试使用RABL创建一个API - 但我的设置与标准设置有点不同 - 正如他们的WIKI中所定义的那样.

我在路由中设置了一个API命名空间:

namespace :api do
  resources :orders
end
Run Code Online (Sandbox Code Playgroud)

我的控制器在/app/controllers/api/orders_controller.rb中

和/app/views/api/orders/index.json.rabl中的我的RABL视图:

当我尝试访问localhost:3000/api/orders时,出现以下错误:

模板丢失了

Missing template api/orders/index with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :haml, :rabl], :formats=>[:html], :locale=>[:en, :en]} in view paths
Run Code Online (Sandbox Code Playgroud)

但是,如果我创建一个名为"/app/views/api/orders/index.html.erb"的新文件,则视图呈现 - 但不使用RABL.

我怎样才能使它使用RABL?

谢谢

rya*_*anb 6

它正在寻找"html"格式.尝试.json在URL中添加扩展名或将路由更改为此.

namespace :api, defaults: {format: 'json'} do
  resources :orders
end
Run Code Online (Sandbox Code Playgroud)