2012-08-30 37 views
4

我正在嘗試使用RABL創建一個API - 但我的設置與標準設置有點不同 - 如其WIKI中定義的那樣。帶RABL的Rails 3 API

我已經安裝在我的路線的API命名空間:

namespace :api do 
    resources :orders 
end 

我/app/controllers/api/orders_controller.rb

內我的控制器和/應用程序中我Rabl的視圖/視圖/ API /命令/ index.json.rabl:

當我試圖訪問本地主機:3000/API /命令,我收到以下錯誤:

模板丟失

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

但是,如果我創建了一個名爲'/app/views/api/orders/index.html.erb'的新文件,該視圖呈現 - 但不使用RABL。

我該如何使它使用RABL?

謝謝

回答

6

它正在尋找「html」格式。嘗試將URL擴展爲.json或將您的路由更改爲此。

namespace :api, defaults: {format: 'json'} do 
    resources :orders 
end