我正嘗試在Rails 5.2中使用Active Storage。我發現,我應該在遷移file
類型創建領域,但我有一個錯誤:無法在Rails中使用ActiveStorage創建文件字段
$ rdm
Running via Spring preloader in process 40193
== 20171217191942 CreateDishes: migrating
=====================================
-- create_table(:dishes)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `file' for #<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x00007fd56e297750>
/Users/alder/Projects/_apps/service_exchange/rails-backend/db/migrate/20171217191942_create_dishes.rb:6:in `block in change'
/Users/alder/Projects/_apps/service_exchange/rails-backend/db/migrate/20171217191942_create_dishes.rb:3:in `change'
-e:1:in `<main>'
遷移:
class CreateDishes < ActiveRecord::Migration[5.2]
def change
create_table :dishes do |t|
t.string :name, index: true
t.string :description
t.file :image
t.timestamps
end
end
end
我試圖創建字符串字段,但它不工作。
找不到關於在official docs
我有主動式存儲遷移和我通過什麼好的
我很確定在rails遷移中沒有這樣的數據類型'文件',請嘗試使用f.string –
檢查此博客:https://rubyinrails.com/2017/07/21/rails-introduces-active- storage-for-file-uploads/ –
所以,是的,我使用了那個鏈接。如果你創建字符串字段,它會在稍後顯示類型不匹配。 – zishe