Configuring erb directory in Sinatra
erb, ruby, sinatra
Solution
You can achieve this by adjusting the configuration settings. Since you are using non-standard settings, you need to tell Sinatra what the actual root of your app is and where to find the views. At the top of your `app/controllers/app.rb` file add:
# sets root as the parent-directory of the current file
set :root, File.join(File.dirname(__FILE__), '..')
# sets the view directory correctly
set :views, Proc.new { File.join(root, "views") }
You can read more about Sinatra configuration options in the Sinatra Documentation.
Problem
app/controllers/app.rb ``` require 'sinatra' get '/' do erb :index end ``` app/views/index.erb ``` <html> <body> <p>Hello World</p> </body> </html> ``` Error: ``` Errno::ENOENT at / No such file or directory - .../app/controllers/views/index.erb ``` How do I configure erb to look into `app/views` instead of `app/controllers/views`?