我真的很喜欢RABL,但它看起来会用.rabl文件把我的视图文件夹弄得乱七八糟。我非常希望有一个独立的API视图目录,所以它应该是这样的:
app/
views/
customers/
index.html.erb
show.html.erb
......
api/
v1/
customers/
index.json.rabl
show.json.rabl实现这一目标的最佳方法是什么?我正在使用这个教程:
http://railscasts.com/episodes/350-rest-api-versioning
来设置版本控制,但它不支持RABL。我已经在app/controllers/api/v1/customers_controller.rb中尝试过了
module Api
module V1
class CustomersController < ApplicationController
respond_to :json
def index
@customers = Customer.search(params[:page])
Rabl::Renderer.json(@customers, 'api/v1/customers/index')
end
end
end
end但正如预期的那样,这似乎并不管用。
发布于 2013-05-18 22:32:27
也有同样的问题。并通过在RABL初始化器中添加以下内容来解决此问题
# config/initializers/rabl_init.rb
require 'rabl'
Rabl.configure do |config|
config.view_paths = [Rails.root.join('app', 'views')]
end如果您想删除此行配置,只需将Rabl::Renderer.json(@customers, 'api/v1/customers/index')更改为config.view_paths = [Rails.root.join('app', 'views', 'api', 'v1')]即可。在控制器中,它会自动链接它。
希望这能有所帮助
发布于 2013-01-29 01:14:09
据我所知,这应该是可行的。我也在做同样的事情。你得到了什么错误?
https://stackoverflow.com/questions/14354760
复制相似问题