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.65k stars 335 forks source link

Cannot find rabl tempate #487

Open geun opened 11 years ago

geun commented 11 years ago

I use rabl in sidekiq. but sometimes error has occurred

error_message is "Cannot find rabl template 'original_texts/original_text' within registered ([\"/home/deploy/chattingcat/releases/20130817133018/app/views/api/v1\", \"/home/deploy/chattingcat/releases/20130817133018/app/views/api/v1\"]) view paths!", "error_class"=>"RuntimeError"

2013-08-20T14:25:49Z 29023 TID-osescrybw WARN: {"retry"=>true, "queue"=>"chats", "class"=>"ChatObjectSendWorker", "args"=>["/chat/new", "OriginalText", 33, "newchat", "original_texts/original_text"], "jid"=>"6ab517fb027eb4293ec0b99b", "enqueued_at"=>1377008749.0405939, "error_message"=>"Cannot find rabl template 'original_texts/original_text' within registered ([\"/home/deploy/chattingcat/releases/20130817133018/app/views/api/v1\", \"/home/deploy/chattingcat/releases/20130817133018/app/views/api/v1\"]) view paths!", "error_class"=>"RuntimeError", "failed_at"=>"2013-08-20T14:25:18Z", "retry_count"=>1, "retried_at"=>2013-08-20 14:25:49 UTC}
2013-08-20T14:25:49Z 29023 TID-osescrybw WARN: Cannot find rabl template 'original_texts/original_text' within registered (["/home/deploy/chattingcat/releases/20130817133018/app/views/api/v1", "/home/deploy/chattingcat/releases/20130817133018/app/views/api/v1"]) view paths!
2013-08-20T14:25:49Z 29023 TID-osescrybw WARN: /home/deploy/chattingcat/shared/bundle/ruby/2.0.0/gems/rabl-0.8.6/lib/rabl/partials.rb:47:in `block in fetch_source'
/home/deploy/chattingcat/shared/bundle/ruby/2.0.0/gems/rabl-0.8.6/lib/rabl.rb:53:in `source_cache'
/home/deploy/chattingcat/shared/bundle/ruby/2.0.0/gems/rabl-0.8.6/lib/rabl/partials.rb:34:in `fetch_source'
/home/deploy/chattingcat/shared/bundle/ruby/2.0.0/gems/rabl-0.8.6/lib/rabl/renderer.rb:61:in `process_source'
/home/deploy/chattingcat/shared/bundle/ruby/2.0.0/gems/rabl-0.8.6/lib/rabl/renderer.rb:35:in `initialize'
/home/deploy/chattingcat/releases/20130817133018/app/workers/chat_object_send_worker.rb:7:in `new'
/home/deploy/chattingcat/releases/20130817133018/app/workers/chat_object_send_worker.rb:7:in `perform'

this is my rabl setting.

require 'rabl'
Rabl.configure do |config|
  config.include_json_root = false
  config.cache_all_output = true
  config.view_paths = [Rails.root.join('app', 'views', 'api', 'v1')]
end
#data = Rabl::Renderer.new(json_view, target, {format: :json, view_path: Rails.root.join('app', 'views', 'api', 'v1')}).render

data = Rabl::Renderer.json(target, json_view)
geun commented 11 years ago

wired view path. Is it correct to use view_path once?

Cannot find rabl template 'original_texts/original_text' within registered (["/home/deploy/chattingcat/releases/20130812101904/app/views/api/v1", "/home/deploy/chattingcat/releases/20130812101904/app/views/api/v1"]) view paths!

nesquena commented 11 years ago

Does that path seem correct, i.e is there a view in that path listed that "/home/deploy/chattingcat/releases/20130812101904/app/views/api/v1/original_texts/original_text'" exists?

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)