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!
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
.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With