John Geliberte John Geliberte - 4 months ago 9
Ruby Question

Errno::ENOENT at / no such file or direcetory

Im currently working on a sinatra app and im having a little problem.

im trying to load my index.erb but sinatra cannot find the index.erb.

Here is my app.rb

require 'rubygems'
require 'sinatra'

module Registration
class HelloWorldApp < Sinatra::Base
get '/' do
erb :index
end
end
end


and this is my Code hierarchy.

enter image description here

It keeps on looking in the directory: Sinatra-Intro/app/views/index.erb
but my views is in the: Sinatra-Intro/views/index.erb

hope you can help me regarding my problem.
thanks

Answer

You need to configure your application instance, something like this should work:

require 'rubygems'
require 'sinatra'

module Registration
  class HelloWorldApp < Sinatra::Base
    configure do
      set :public_folder  , File.expand_path('../public', __FILE__)
      set :views          , File.expand_path('../views', __FILE__)
      set :root           , File.dirname(__FILE__)
      set :show_exceptions, development?

      # Optional: Load from external file
      #YAML.load_file('path/to/config.yml').each do |k, v|
      #  set(k.to_sym, v)
      #end
    end

    get '/' do
      erb :index
    end
  end
end

Then:

bundle exec rackup
Comments