我是Ruby和Sinatra的新手,我正在尝试完成本教程:http://www.sitepoint.com/just-do-it-learn-sinatra-iv/
在本教程结束时,在部署之前,教程说“在我们继续部署应用程序之前,我们应该检查一下在我们的本地计算机上运行正常。这是以不同的方式完成的有一个架子文件。“然后它指示学生在命令行输入“rackup”。当我这样做,然后转到浏览器中指定的9292本地端口我收到错误:
DataObjects::ConnectionError at / file is encrypted or is not a database
但是当我通过在同一目录中键入“ruby main.rb”来运行我的应用程序时,该应用程序在我的浏览器中正常工作。教程错了吗?我可以将我的应用程序部署到Heroku吗?或者我是否需要使用rackup命令使其工作?
我正在使用sqlite3 1.3.9和ruby 2.0.0
这是我的'main.rb'文件:
require 'sinatra'
require 'data_mapper'
require 'slim'
require 'sass'
DataMapper.setup(:default, 'sqlite3::memory:')
class Task
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
property :completed_at, DateTime
belongs_to :list
end
class List
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
has n, :tasks, :constraint => :destroy
end
Task.auto_upgrade!
List.auto_upgrade!
#checks integrty of models
DataMapper.finalize
#For using SASS
get('/styles.css'){ content_type 'text/css', :charset => 'utf-8' ; scss :styles }
get '/' do
@lists = List.all(:order => [:name])
slim :index
end
post '/:id' do
List.get(params[:id]).tasks.create params['task']
redirect to('/')
end
delete '/task/:id' do
Task.get(params[:id]).destroy
redirect to('/')
end
#this adds a button that toggles a checkmark on and off
#so you can check something off your list
put '/task/:id' do
task = Task.get params[:id]
task.completed_at = task.completed_at.nil? ? Time.now : nil
task.save
redirect to('/')
end
post '/new/list' do
List.create params['list']
redirect to('/')
end
delete '/list/:id' do
List.get(params[:id]).destroy
redirect to('/')
end
我的config.ru文件:
require 'bundler'
Bundler.require
require './main'
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")
run Sinatra::Application
和我的Gemfile
source :rubygems
gem "sinatra"
gem "datamapper"
gem "slim"
gem "sass"
gem "dm-postgres-adapter", :group => :production
gem "dm-sqlite-adapter", :group => :development
gem 'tilt', '~> 1.4.1'
我在.bundle文件夹中也有一个配置文件,上面写着
---
BUNDLE_WITHOUT: production
我不知道从哪里开始。
我的代码在几个方面已经不同于最终代码: https://github.com/daz4126/Just-Do-It
因为我已经遇到了一些错误,我必须为此做出解决方法。复制粘贴最终代码并不能使其正常工作。
提前致谢。我有其他文件可以发布,只是想到相关文件是这些。