eucalypt
Search…
Views

Location

The view files are located in the app/views directory.

Rendering

Eucalypt looks for view files relative to the app/views directory by default (though you can change this in the core application file).

Views directly inside directory

If your views folder structure is like the following:
1
views
2
├── partials
3
├── layouts
4
├── index.erb
5
└── 404.erb
Copied!
Then you can render the pages index.erb and 404.erb in the following way:
app/controllers/main_controller.rb
1
class MainController < ApplicationController
2
helpers MainHelper if defined? MainHelper
3
4
get '/' do
5
erb :index
6
end
7
8
error Sinatra::NotFound do
9
erb :"404"
10
end
11
end
Copied!

Views inside sub-directories

If your views folder structure is like the following (with some views located within sub-directories):
1
views
2
├── partials
3
├── layouts
4
├── pages
5
│ ├── index.erb
6
│ └── about.erb
7
└── 404.erb
Copied!
Then you can render the pages index.erb and 404.erb in the following way (note the specification of the full path relative to app/views for rendering the index page):
app/controllers/main_controller.rb
1
class MainController < ApplicationController
2
helpers MainHelper if defined? MainHelper
3
4
get '/' do
5
erb :"pages/index"
6
end
7
8
error Sinatra::NotFound do
9
erb :"404"
10
end
11
end
Copied!
Last modified 2yr ago
Copy link