1
CarrierWave에 문제가 있습니다. 데이터베이스의 이미지 및 경로는 저장되지 않지만 tmp 파일은 저장됩니다.CarrierWave : 이미지 저장 안 함 (tmp 만 해당)
은 여기 내 AvatarUploader (응용 프로그램/업 로더/avatar_uploader.rb)입니다 :
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end
그리고 여기 회원 모델 (애플 리케이션/모델/member.rb)입니다 :
class Member < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation, :avatar
mount_uploader :avatar, AvatarUploader
email_regex = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :name, presence: true,
uniqueness: true,
length: { within: 4..32 }
validates :email, presence: true,
uniqueness: true,
format: { with: email_regex }
validates :password, presence: true,
length: { minimum: 6 }
has_secure_password
before_create :generate_token
private
def generate_token
begin
self.auth_token = SecureRandom.hex(16)
end while Member.exists?(auth_token: self.auth_token)
end
end
어떤 아이디어?
하나의 CW ActiveRecord 지원이 설치되어 있고 'avatar' 문자열 열을 추가했지만 캐시 된 버전의 파일로 회원을 저장해야합니다. https://github.com/jnicklas/carrierwave의 ActiveRecord 부분을 참조하십시오. 게시 된 코드에서 어디서나 볼 수 없기 때문에 추측 할 수 있습니다. 그렇지 않으면 나에게 잘 보입니다. –
어떻게 수리해야할지 모르겠다. ( – rgtk
위의 GitHub 링크와 관련된 ReadMe에 나와있는 단계를 따라 가면서 (스크롤을 내려서) 시도해보십시오. 작은 설정 단계가 많이 필요합니다. CarrierWave는 코드를 통해 무엇을하는지 알기를 강력히 권장하며, 많은 일을하는 강력한 보석입니다. 도움이 더 필요하면'Member' 레코드를 저장하는 컨트롤러 코드를 포함하도록 게시물을 편집하십시오 이것은 파일의 캐시 된 버전이 상점에 쓰여지는 지점이며, 데이터베이스는 이름으로 업데이트되며 대부분의 다른 마술이 발생합니다. –