Why would I get “Errno::ENOENT: No such file or directory” when viewing a Sinatra form?

◇◆丶佛笑我妖孽 提交于 2019-12-07 22:58:11

问题


I am trying to follow this tutorial:
http://net.tutsplus.com/tutorials/ruby/singing-with-sinatra/

Got stuck in "We’ll also make use of a “view file”, which allows us to split the markup for a view into a separate file. "

I have my basics.rb file running fine.

And My files are stored as follows:

Desktop/RubyForm/basics.rb
Desktop/RubyForm/view/form.erb 

However, now when i go to http://localhost:9393/form , I am greeted with:

Errno::EIO at /form 
Input/output error - <STDERR> file: lint.rb location: write line: 398
sinatra.error   
Errno::ENOENT: No such file or directory - 
  /Users/HelenasMac/Desktop/views/form.erb



UPDATE! :
Got the form to work right after running ruby basics.rb and going to http://localhost:4567/form . However, after I run "shotgun basics.rb" , I have to go to http://localhost:9393/form, and that's when the form doesn't show up.

What am I doing wrong? Disclaimer: mega beginner to ruby and using the terminal.

Thanks in advance!


回答1:


If you cannot get shotgun to work then the new recommended way to reload Sinatra seems to be rerun.

To use it:

> gem install rerun
> cd /Users/HelenasMac/Desktop/RubyForm
> rerun ruby basics.rb



回答2:


Explicity Set a Views Directory

Unless you're using inline template for your views with enable :inline_templates, you may need to explicitly define a template directory if the default values aren't working for you. The docs describe how to set your views directory as follows:

:views - view template directory

A string specifying the directory where view templates are located. By default, this is assumed to be a directory named “views” within the application’s root directory (see the :root setting). The best way to specify an alternative directory name within the root of the application is to use a deferred value that references the :root setting:

set :views, Proc.new { File.join(root, "templates") }

You may also need to explicitly set :root, and make sure that both :root and :views make sense from your current working directory.



来源:https://stackoverflow.com/questions/14366687/why-would-i-get-errnoenoent-no-such-file-or-directory-when-viewing-a-sinatr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!