我正在尝试使用 rails-api 中的 rabl 模板系统。
rabl 在 View 路径中查找模板,rails-api 忽略了这一点。
我将如何设置 rabl-rails,我已将以下行包含到我的 Controller 中。
include ActionController::MimeResponds
include ActionController::ImplicitRender
respond_to :json
但是: json:@deal 使用标准 rails 呈现。 Renderer.json(@deal) 未定义,我认为它可以与 rabl 一起使用。
如有任何帮助,我们将不胜感激。
最佳答案
添加:
config.view_paths = ['/app/views']
到 config/initializers/rabl_init.rb
。不需要 rabl-rails
,使用普通的 rabl
,不需要那些 include
,不需要 respond_to
。
渲染:
render 'foo/bar' # will render app/views/foo/bar.rabl template
关于ruby-on-rails - 使用 rabl-rails 设置 rails-api gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24795494/