nesquena / rabl

General ruby templating with json, bson, xml, plist and msgpack support
http://blog.codepath.com/2011/06/27/building-a-platform-api-on-rails/
MIT License
3.64k stars 334 forks source link

Is it wrong view_path? #645

Open mojidabckuu opened 9 years ago

mojidabckuu commented 9 years ago

At first I faced with an issue when I was using explicit render. The issue that my helper methods from controllers are now available inside rabl templates.

Rabl::Renderer.json(@paths, 'api/v1/paths/index')

I fixed this one using https://github.com/nesquena/rabl/issues/231

Rabl::Renderer.json(@paths, 'api/v1/paths/index', :scope => self)

But now I found issue that rabl tries to find template in the wrong place (Missing template api/v1/paths/popular, api/api/popular with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :rabl]}. Searched in:

Here is my config

require 'rabl'
Rabl.configure do |config|
  config.include_json_root = false
  config.view_paths = ['app/views']
  # config.perform_caching = true
  # config.exclude_nil_values = true
end
alexisraca commented 7 years ago

When you have scoped views, the weird pathing in rabl concats the paths, so a way to fit the exact path is (worked for me while debuging the gem):

Rabl::Renderer.json(objects, 'app/views/scoped/directories/resource', view_path: Rails.root.to_s) or try adding Rails.root.to_s + "/app/views" to your

config.view_paths