Reputation: 1749
I'm learning Ruby-on-Rails
. For this I have a 'hello world' sample.
Thats my config/routes.rb
:
Rails.application.routes.draw do
root 'application#show'
end
controllers/application_controller.rb
:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def show
render 'startpage'
end
end
And finally my views/startpage.html.erb
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Hello World!</title>
</head>
<body id="index" class="home"><h1>Hello World!!</h1>
</body>
</html>
But when I open my site I get this error:
Template is missing
Missing template application/startpage with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "/home/ubuntu/workspace/app/views"
So, am I missing something or has the startpage.html.erb
file somewhere else?
Upvotes: 1
Views: 1389
Reputation: 8900
Your template would need to be inside of /views/application
for the convention to work.
Rails looks inside of /views/CONTROLLER/action
by convention without specifying a specific location.
/views/application/startpage.html.erb
should work in your situation.
Bonus learning points:
A common practice I see for creating normal, static pages, is a PagesController
which handles each of them. Doing this, your route would point to pages#startpage
and your view would be inside of /views/pages/startpage.html.erb
-- Just a tip!
Upvotes: 1