加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 带RABL的Rails 3 API

发布时间:2020-12-17 03:03:47 所属栏目:百科 来源:网络整理
导读:我正在尝试使用RABL创建一个API – 但我的设置与标准设置有点不同 – 正如他们的WIKI中所定义的那样. 我在路由中设置了一个API命名空间: namespace :api do resources :ordersend 我的控制器在/app/controllers/api/orders_controller.rb中 和/app/views/ap
我正在尝试使用RABL创建一个API – 但我的设置与标准设置有点不同 – 正如他们的WIKI中所定义的那样.

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

namespace :api do
  resources :orders
end

我的控制器在/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

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

我怎样才能使它使用RABL?

谢谢

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读