Errno::ENOENT 在/没有那个文件或目录
Errno::ENOENT at / no such file or directory
我目前正在开发一个 sinatra 应用程序,我遇到了一个小问题。
我正在尝试加载我的 index.erb,但 sinatra 找不到 index.erb。
这是我的app.rb
require 'rubygems'
require 'sinatra'
module Registration
class HelloWorldApp < Sinatra::Base
get '/' do
erb :index
end
end
end
这是我的代码层次结构。
它继续在目录中查找:Sinatra-Intro/app/views/index.erb
但我的观点是:Sinatra-Intro/views/index.erb
您可以使用视图设置更改默认位置。像这样:
set :views, Proc.new { File.join(root, "views") }
您需要配置您的应用程序实例,像这样应该可以工作:
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
然后:
bundle exec rackup
我目前正在开发一个 sinatra 应用程序,我遇到了一个小问题。
我正在尝试加载我的 index.erb,但 sinatra 找不到 index.erb。
这是我的app.rb
require 'rubygems'
require 'sinatra'
module Registration
class HelloWorldApp < Sinatra::Base
get '/' do
erb :index
end
end
end
这是我的代码层次结构。
它继续在目录中查找:Sinatra-Intro/app/views/index.erb 但我的观点是:Sinatra-Intro/views/index.erb
您可以使用视图设置更改默认位置。像这样:
set :views, Proc.new { File.join(root, "views") }
您需要配置您的应用程序实例,像这样应该可以工作:
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
然后:
bundle exec rackup