0
我正在使用carrierwave将图像上传到我的webapp。Rails Carrierwave stor_dir位置无效(型号#{关联}返回零)
已经有必要将它们上传到父模型的位置。
即,
父母是有许多图像的房子。
所以我想将图像存储在
public/uploads/houses/images/[:house_id]/
这是我的当前设置。
..uploaders/image_uploader.rb
def store_dir
puts "uploads/house/#{model.house_id}/#{mounted_as}/#{model.id}"
"uploads/house/#{model.house_id}/#{mounted_as}/#{model.id}"
end
puts语句打印出我想要的正确路径,但保存的路径不匹配。 看来,model.house_id被返回nil
房屋模型
class House < ActiveRecord::Base
attr_accessible :address, :description, :title, :price, :image, :image_id, :images, :image_cache
has_many :images
mount_uploader :image, ImageUploader
end
图像模型
class Image < ActiveRecord::Base
attr_accessible :house_id, :image
mount_uploader :image, ImageUploader
belongs_to :house
end
如何获取正确的路径/我在做什么错:(