rabl: Templates not found in view path

So I have my template in a namespaced Engine app/views/scheduler/schedules/show

Rabl::Renderer.new(
  'schedules/show',
  @schedules,
  view_path: 'app/views/scheduler',
  format: :json
).render
Rabl::Renderer.json(
  @schedules,
  'schedules/show',
  view_path: 'app/views/scheduler'
)

Both raises this error

Cannot find rabl template 'schedules/show' within registered (["app/views/scheduler"]) view paths!

However it does work in my specs within the Engine but not when using the Engine from the parent app.

rails (3.2.8) rabl (0.7.2)

About this issue

  • Original URL
  • State: open
  • Created 12 years ago
  • Comments: 23 (7 by maintainers)

Most upvoted comments

Debuging this worked for me in the controllers

render inline: Rabl::Renderer.xml(@login, “app/views/scoped_directory/logins/show”, view_path: Rails.root.to_s)

@kmalakoff, when I’ve wanted to point to paths within an engine, one approach is to create a method in the engine, that returns the path relative to the engine.

So in my_engine/lib/my_engine.rb I’d create a method like this:

module MyEngine

  def self.path_to_views
    File.expand_path("../app/views/my_engine", File.dirname(__FILE__))
  end

  ......
end

Then in the host app I can add:

config.view_paths << MyEngine.path_to_views

For example, look at active_admin_load_path here:

https://github.com/reggieb/qwester/blob/master/lib/qwester.rb

Ok, so observations so far:

  • Using render in the controller doesn’t work with the namespaced views either (doesn’t matter if view_paths is set by Rabl.configure).
  • Using the full file systems path as of example in #238 doesn’t work either.
  • Adding the namespace to the view name argument doesn’t work 'isolated_engine/nested_items/show'
  • If I move the template out of the namespaced folder it works.