我有一个非常小的Rails应用程序,适用于几乎只提供静态内容的客户端。它在后台没有数据库。
我的客户现在需要一种方法来提供主页上显示的小文本。在其中,他想说明他的产品的当前交付期限(变化很大)。最简单的事情是一个小页面,他可以在textarea中更改文本,并受密码保护。
我想知道是否有一种非常简单的方法可以提供类似的东西,而无需将完整的数据库附加到应用程序中?
答案 0 :(得分:0)
SQLite3数据库是最简单的,它只是作为文件保存在db/
目录(schema.rb
等旁边),因此不需要设置其他任何东西。这是新Rails应用程序的默认设置,因此甚至可能已经存在,如果不是database.yml
只需要使用sqlite3
适配器,database
是文件路径,例如:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
即使这样太多,也没有什么能阻止你使用普通文件来处理简单的事情,无论是纯文本还是JSON,或其他什么。
e.g。 str = IO.read file_name
和IO.write file_name, str
。对于JSON,您可以使用stdlib JSON
模块。