Rails "Template is missing" error, though it exists (3.2.1)

14,750

Solution 1

You say you have app/views/home/pages/index.html.erb to represent the index view for your pages resource. I think the home/ directory is not required.

In other words, your view file should be app/views/pages/index.html.erb.

Solution 2

It's looking to find it in app/views/pages/index but you have it in app/views/home/pages/index. That slight difference makes it so that the Rails convention is lost.

If you must keep your new directory hierarchy, do this on your controller:

class PagesController < ApplicationController
  def index
    render :partial => "home/pages/index"
  end
end

But, by default, if you have a resource, like :pages, it will automatically look in app/views/pages.

Share:
14,750
hidenori
Author by

hidenori

Updated on June 04, 2022

Comments

  • hidenori
    hidenori almost 2 years

    I just started using Rails and am not sure what I'm not doing correctly.

    In routes.rb I have

    resources :pages
    

    In app/controllers/pages_controller.rb I have

    class PagesController < ApplicationController
      def index
      end
    end
    

    I have a layout in app/views/layouts/application.html.erb and a template in app/views/home/pages/index.html.erb which I want rendered when I request "/pages". However, I get the error

    Template is missing

    Missing template pages/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/###/app/views"

    I've been using stackoverflow for ages without posting, but so many different things seem to trigger this error that it's hard to find answers for my particular case. Also I'm a noob :3 Please help!

  • hidenori
    hidenori about 12 years
    Thanks! Looks like this was a lack-of-sleep error :p I'd upvote you if I could.
  • hidenori
    hidenori about 12 years
    Thanks for the extra information! I personally don't need to do this, but someone else might.