zis*_*she 6 ruby ruby-on-rails ruby-on-rails-5 rails-activestorage ruby-on-rails-5.2
我正在尝试在Rails 5.2中使用Active Storage.我发现我应该file在迁移中创建具有类型的字段,但是我有一个错误:
$ 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>'
Run Code Online (Sandbox Code Playgroud)
移民:
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
Run Code Online (Sandbox Code Playgroud)
我试图创建字符串字段,但它不起作用.
在官方文档中找不到任何相关内容
我有迁移活动存储,我通过了确定
sma*_*ton 11
相反,你需要在自己的迁移(创建一个专门的领域t.file :image)活动的存储使用两个表,你的设置有 rails active_storage:install.当您设置storage.yml时,您应该可以使用
has_one_attached :image
Run Code Online (Sandbox Code Playgroud)
在Dishes模型中没有创建image列.