Unable to create field with ActiveStorage in Rails

I am trying to use Active Storage in Rails 5.2. I found that I should create a field with a type filein the migration, but I have an error:

$ 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>'

Migration:

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

I tried to create a string field, but it does not work.

Could not find anything about this in official docs

I have a migration for active storage and I went fine

+4
source share
2 answers

, (t.file :image), , setup rails active_storage:install. storage.yml,

has_one_attached :image

Dishes image.

+10

( ActiveRecord), file, , , string like t.string

+4

Source: https://habr.com/ru/post/1690943/


All Articles