ActionView::MissingTemplate: Rails not looking for JSON format - ruby-on-rails

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.

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' ...

Related

Missing template error for Ruby on Rails Application

I have a view in the LoginController with the following code
def home
render 'home'
end
However, whenever I load my web server, it shows the error message:
ActionView::MissingTemplate (Missing template login/home, application/home with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in:
* "C:/Users/60984/prairielearn-eecs/app/views"
* "C:/Ruby30/lib/ruby/gems/3.0.0/gems/actiontext-6.1.7.2/app/views"
* "C:/Ruby30/lib/ruby/gems/3.0.0/gems/actionmailbox-6.1.7.2/app/views"
):
app/controllers/login_controller.rb:16:in `home'
Even though I have the file in the directory app/views/login/home.html.erb.
I tried changing it to a more specific directory such as
def home
render 'login/home'
end
but it still fails. However, I tried using the whole path like
render file: 'C:/Users/.../app/views/login/home.html.erb'
With the code above, the problem changed into the html.erb is not being interpreted, it will display the code blocks on the browser no matter what browser I use.
I am just confused about why it doesn’t work since I have the html file in the designated place.

Rails missing template for JS file

On my application controller I have a method where I'm trying to render a specific JS file located in the folder lib/assets/api/v1/
lib = render_to_string File.join(Rails.root,"/lib/assets/api/v1/shasync.js")
render :text => lib
The problem is that I'm getting the following MissingTemplate error:
ActionView::MissingTemplate (Missing template Users/name/Projects/project/lib/assets/api/v1/shasync.js with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/name/Projects/project/app/views"
* "/Users/name/.rvm/gems/ruby-2.2.1/gems/devise-3.5.2/app/views"
* "/Users/name/.rvm/gems/ruby-2.2.1/gems/shopify_app-6.2.0/app/views"):
Can anyone help please? I did this in the past and it worked, don't know why it's not working anymore.

In rails what else should you do to render a file in footer?

I am a beginner in rails and I have to add a footer to my site.
I just copied the line in the application.html where it renders a file
= render :partial => "shared/navigation"
and put my file
= render :partial => "shared/footer"
Then in the shared folder I created my file _footer.html.haml and put my html code there.
But the site gives me the following error:
ActionView::MissingTemplate at /
Missing template shared/footer with {:locale=>[:en], :formats=>[:html]...
What else should I do so that rails can fetch that file like any other file from the shared folder?
Thanks!
Edit: Full error is this one:
ActionView::MissingTemplate - Missing partial shared/footer with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml, :rjs]}. Searched in:
* "/home/username/workspace/myapp/app/views"

Mysterious "Missing Template"

I don't know if there is a better way to do this than to simply link to my (very small) rails app on Githb... https://github.com/MaxPleaner/someapp
The issue right not is a weird "missing template" error at /notes/new
I made a corresponding view so I'm not sure why this step is making an error.
The view is called 'new.html.erb' and the link is written like this:
<%= link_to "link text...", :controller => "notes", :action => "new" %>
The error says -
Template is missing
Missing template notes/new, application/new with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/home/macs/Desktop/playapp/app/app/views" * "/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/twitter-bootstrap-rails-2.2.8/app/views"
Thanks a lot.
Your new.html is in the wrong folder. You have it in views/notes/new.html.erb Move that into app/views/notes/new.html.erb

Rails doesn't seem to be looking for partial in the same directory

I'm working on exercise 3 in Chapter 10 of Michael Hartl's The Ruby on Rails Tutorial.
I'm refactoring code in app/views/static_pages/home.html.erb and moving it into the two partials:
app/view/static_pages/_signed_in.html.erb
app/view/static_pages/_non_signed_in.html.erb
and calling render on both files. For some reason I get this error:
ActionView::Template::Error:
Missing partial static_pages/non_signed_in, application/non_signed_in with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}.
However, when I move the two partials to the sibling directory app/view/static_pages/shared and tell render to look there (i.e. "render 'shared/signed_in'" and "render 'shared/non_signed_in'"), the error disappear. Thoughts?
Thanks!!

Resources