SQLite3& Unicorn - 如何设置数据库以允许写入?

时间:2015-03-25 22:44:42

标签: ruby-on-rails nginx sqlite unicorn digital-ocean

我部署了一个网站,我希望允许用户填写表单。但是,无法写入表单,因为数据库当前是只读的!如何更改SQLite3以允许任何用户写入数据库?

这是我的Unicorn.log:

root@The-Origin-of-Foods:/home/unicorn# tail -20 log
tail: error reading ‘log’: Is a directory
root@The-Origin-of-Foods:/home/unicorn# cd log
root@The-Origin-of-Foods:/home/unicorn/log# ls
unicorn.log
root@The-Origin-of-Foods:/home/unicorn/log# tail -20 unicorn.log
  Parameters: {"id"=>"3"}
  Food Load (1.9ms)  SELECT  "foods".* FROM "foods" WHERE "foods"."id" = ? LIMIT 1  [["id", 3]]
  Food Load (3.8ms)  SELECT "foods".* FROM "foods"
  Rendered foods/_form.html.erb (10.2ms)
  Rendered foods/edit.html.erb within layouts/application (15.5ms)
Completed 200 OK in 44ms (Views: 20.7ms | ActiveRecord: 5.6ms)
Started PATCH "/foods/3" for 135.23.129.198 at 2015-03-25 22:35:07 +0000
Processing by FoodsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"hmexKPwxoAvbU9mhgOr7DJnI7PAx92KgTT1ZhHqOnJiiwx2lj4Roi/eoOR1U7EajIxgyyww4rHZaoAG7E+IT6A==", "food"=>{"name"=>"sfasdf", "sciname"=>"asdfj", "origin"=>"asdf", "description"=>"sadf", "years"=>"sdf", "source"=>"hfvjkhj"}, "commit"=>"Update", "id"=>"3"}
  Food Load (1.7ms)  SELECT  "foods".* FROM "foods" WHERE "foods"."id" = ? LIMIT 1  [["id", 3]]
   (0.6ms)  begin transaction
  SQL (1.9ms)  UPDATE "foods" SET "sciname" = ?, "updated_at" = ? WHERE "foods"."id" = ?  [["sciname", "asdfj"], ["updated_at", "2015-03-25 22:35:07.663449"], ["id", 3]]
SQLite3::ReadOnlyException: attempt to write a readonly database: UPDATE "foods" SET "sciname" = ?, "updated_at" = ? WHERE "foods"."id" = ?
   (0.3ms)  rollback transaction
Completed 500 Internal Server Error in 45ms

ActiveRecord::StatementInvalid (SQLite3::ReadOnlyException: attempt to write a readonly database: UPDATE "foods" SET "sciname" = ?, "updated_at" = ? WHERE "foods"."id" = ?):
  app/controllers/foods_controller.rb:36:in `update'

我在DigitalOcean VPS上使用Nginx和Unicorn。 Rails 4.2和Ruby 2.1.3

1 个答案:

答案 0 :(得分:1)

好的,所以解决方案是使用chmod来更改文件的权限。 我在db / production.sqlite3中找到了我的数据库。然后我用命令行输入:

chmod 777 production.sqlite3

chmod允许我更改权限和类,每种类型有3种类型:读取,写入,执行和所有者,组,其他。 777是一个数字代码,用于设置这些权限和类的值。你可以在这里阅读更多相关信息http://www.maketecheasier.com/file-permissions-what-does-chmod-777-means/