ActionView::MissingTemplate: Rails not looking for JSON format

3.1k Views Asked by At

I'm using Backbone.js and thus bootstrapping data using a JSON (jbuilder) partial like so (using HAML):

App.users = new App.UserList(#{render('users/index', :formats => [:json], :handlers => [:jbuilder], locals: {users: @users})})}, {silent:true});

It gives me this error:

ActionView::Template::Error (Missing partial users/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :jbuilder, :arb, :coffee, :haml]}. Searched in:

Notice that it is only looking for the ':html' format, despite me passing in 'formats: [:json]'. Should I be doing something differently?

Thank you for any help.

1

There are 1 best solutions below

1
On BEST ANSWER

What version of Rails are you using? This problem was fixed for 3.2.3, but exists in earlier versions.

For a quick fix, though it will cause deprecation warnings in Rails 3.2 and later, you can add the format to the name of the template, i.e. render('users/index.json' ...