我一直试图绕过Rails 5 ActiveStorage,我似乎错过了连接点的方法 . 我想要设置的基本结构是具有许多Image模型的Composition模型 . 每个Image模型都有一个附加的图像文件 . (我认为我已经正确完成了所有迁移,以便设置Active Storage) .

这可能是错的,但这是我设置的当前模型:

// relevant bits from composition controller
def create
  @composition = Composition.create(composition_params)
  render 'show'
end

def composition_params
    params.require(:composition).permit(:name, :description, :dimension, :materials, image: [:name, :file, :description])
end

class Composition < ApplicationRecord
    has_many :images
    accepts_nested_attributes_for :images
end

class Image < ApplicationRecord
    belongs_to :composition
    has_one_attached :file
end

在尝试使用React进行任何操作之前,我一直试图用postman命中 endpoints (一旦我弄清楚如何在Postman上格式化表单数据我应该可以让React格式化数据,我对JS更加舒服事情的一面) .

我的模特一般都在朝着正确的方向前进吗?我试打的测试POST有一个表单数据,如composition [name] => name,composition [image] [file] => test_file.png,但是我得到了400个错误请求和一堆garbledeegook我不能读入终端输出(字面意思是随处可见的字符) . 希望其他人通过ActiveStorage使用JSON Rails API后端进行文件使用 .