【问题标题】:Unable to upload seed data with Attachinary gem "Undefined method `photos_urls=' for object"无法使用附件 gem 上传种子数据“对象的未定义方法 `photos_urls='”
【发布时间】:2018-04-04 18:35:39
【问题描述】:

我正在尝试为我的 Photoshoot 模型上传种子数据,该模型由多个 for url 组成,如下所示:

10.times {
  urls = [
    'http://lorempixel.com/400/400/',
    'http://lorempixel.com/400/400/',
    'http://lorempixel.com/400/400/',
    'http://lorempixel.com/400/400/',
    'http://lorempixel.com/400/400/',
    'http://lorempixel.com/400/400/',
    'http://lorempixel.com/400/400/',
    'http://lorempixel.com/400/400/'
  ]
  time = Faker::Time.between(DateTime.now - 1, DateTime.now + 3)
  photoshoot = Photoshoot.new( user_id: Faker::Number.between(1, 19), photograph_id: Faker::Number.between(1, 19), start_time: time, end_time: time + Faker::Number.between(1, 2).hours, message: Faker::TheFreshPrinceOfBelAir.quote )
  photoshoot.save!
  photoshoot.photo_urls = urls
}

但我在种子中收到以下错误消息:

NoMethodError:

的未定义方法 `photos_urls='

我的模型如下:

class Photoshoot < ApplicationRecord
  has_attachment :photos, maximum: 20
  belongs_to :photograph
  belongs_to :user
end

【问题讨论】:

    标签: ruby-on-rails ruby cloudinary


    【解决方案1】:

    添加附件路径

    has_attached_file :photo,
    :styles => {
    :thumb=> "",
    :small  => ""},
    :path => "uploads/:class/:attachment/:id_partition/:style/:basename.:extension",
    :url => "uploads/:class/:attachment/:id/:style/:basename.:extension"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      • 2015-03-26
      • 1970-01-01
      相关资源
      最近更新 更多