【发布时间】:2021-07-07 15:16:29
【问题描述】:
我有一个子例程,它生成一个 .mp4 文件,然后使用该文件的唯一标识符调用一个 ruby 脚本。 该文件类似于文件系统:
/opt/program/records/123345_record.mp4
文件名中的数字代表唯一的修饰符,ruby 脚本知道。现在我想将这个生成的文件存储在数据库中。我已经准备好带有相应迁移文件的架构文件,因此该表有一个额外的文件列。
ActiveRecord::Schema.define(version: 2021_04_12_123013) do
create_table "articles", force: :cascade do |t|
t.string "title"
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.binary "file", limit: 104857600
end
end
但是如何将文件存储在模型/迁移文件中定义的行中? 在articles_controller.rb 我可以定义一个方法,可以这样调用:
def add_file
end
这还不够,但我不知道如何用当前存储在文件系统上的数据填充新字段“文件”。
【问题讨论】:
标签: ruby-on-rails ruby database store