Sinatra cannot find submission catalog

I am trying to structure my Sinatra application in such a way that it looks like a regular Ruby Gem structure. I have the following file tree:

. โ”œโ”€โ”€ app.rb โ”œโ”€โ”€ config.ru โ”œโ”€โ”€ Gemfile โ”œโ”€โ”€ Gemfile.lock โ”œโ”€โ”€ helpers โ”‚  โ”œโ”€โ”€ dbconfig.rb โ”‚  โ”œโ”€โ”€ functions.rb โ”‚  โ””โ”€โ”€ init.rb โ”œโ”€โ”€ hidden โ”‚  โ””โ”€โ”€ Rakefile โ”œโ”€โ”€ lib โ”‚  โ”œโ”€โ”€ admin.rb โ”‚  โ”œโ”€โ”€ api.rb โ”‚  โ”œโ”€โ”€ indexer.rb โ”‚  โ”œโ”€โ”€ init.rb โ”‚  โ””โ”€โ”€ magnet.rb โ”œโ”€โ”€ models โ”‚  โ”œโ”€โ”€ init.rb โ”‚  โ”œโ”€โ”€ invite.rb โ”‚  โ”œโ”€โ”€ tag.rb โ”‚  โ”œโ”€โ”€ torrent.rb โ”‚  โ””โ”€โ”€ user.rb โ”œโ”€โ”€ public โ”‚  โ”œโ”€โ”€ css โ”‚  โ”‚  โ”œโ”€โ”€ reset.css โ”‚  โ”‚  โ””โ”€โ”€ style.css โ”‚  โ”œโ”€โ”€ i โ”‚  โ”œโ”€โ”€ img โ”‚  โ”‚  โ”œโ”€โ”€ bg.jpg โ”‚  โ”‚  โ”œโ”€โ”€ dl-icon.png โ”‚  โ”‚  โ”œโ”€โ”€ logo.png โ”‚  โ”‚  โ”œโ”€โ”€ logo-public.png โ”‚  โ”‚  โ”œโ”€โ”€ magnet-icon.png โ”‚  โ”‚  โ”œโ”€โ”€ text-logo.png โ”‚  โ”‚  โ”œโ”€โ”€ text-logo-public.png โ”‚  โ”‚  โ””โ”€โ”€ upload-icon.png โ”‚  โ””โ”€โ”€ js โ”‚  โ”œโ”€โ”€ main.js โ”‚  โ””โ”€โ”€ torrents.js โ”œโ”€โ”€ README.md โ”œโ”€โ”€ SPEC.md โ”œโ”€โ”€ tmp โ”‚  โ””โ”€โ”€ restart.txt โ”œโ”€โ”€ TODO.md โ””โ”€โ”€ views โ”œโ”€โ”€ error.erb โ”œโ”€โ”€ footer.erb โ”œโ”€โ”€ header.erb โ”œโ”€โ”€ index.erb โ”œโ”€โ”€ list.erb โ”œโ”€โ”€ nav.erb โ”œโ”€โ”€ text.erb โ””โ”€โ”€ upload.erb 

I have application files that try to map objects to lib/ , but after (re) starting the Passenger server I get: Errno::ENOENT - No such file or directory - /home/dev/indexer/lib/views/index.erb

Offensive lines:

 get '/' do erb :index end 

How can i fix this?

+4
source share
3 answers

Specify the path to the view directory in your configuration block:

 set :views, "#{settings.root}/../views" 

See http://www.sinatrarb.com/configuration.html#__view_template_directory

+3
source

Despite the contents of the rb files, it would be hard to guess what was wrong. If the routes are specified in the rb files in a subfolder inside the root directory of your application, you will need to explicitly set the views folder.

In your case, if /app.rb is the file that sets up the basic configuration, you will need to install views (or something else like that in the shared folder).

 class MyApp < Sinatra::Base set :views, File.dirname(__FILE__) + '/views' set :public_folder, File.dirname(__FILE__) + '/public' end 

Else Sinatra will search in subsequent subfolders for the corresponding paths. In addition, subsequent route files must extend to the same class. In this case, MyApp. For example, in ./lib/admin.rb

 class MyApp < Sinatra::Base get "/blah" do "blah blah" end end 
+3
source

Ok, I found out what happened! All I had to do was make my classes in the lib/ folder inherit from the main Brightswipe class, which is inherited from Sinatra::Base .

0
source

All Articles