Ruby on rails 在rails中使用Carrierwave时出错
我有一个网站,其中包含许多用户,每个用户都有自己的个人资料我想让他们通过carrierwave gem上传那里的图像,但我得到一个循环,有以下错误,这是我第一次使用carrierwave gem:(: 这是载波宝石:Ruby on rails 在rails中使用Carrierwave时出错,ruby-on-rails,ruby,ruby-on-rails-4,carrierwave,Ruby On Rails,Ruby,Ruby On Rails 4,Carrierwave,我有一个网站,其中包含许多用户,每个用户都有自己的个人资料我想让他们通过carrierwave gem上传那里的图像,但我得到一个循环,有以下错误,这是我第一次使用carrierwave gem:(: 这是载波宝石: class ImageUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick storage :file # Override the directory where upload
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
# 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
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_limit => [200, 200]
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
end
class ImageUploader[200200]
结束
#添加允许上载的扩展的白名单。
#对于图像,您可以使用以下内容:
def扩展白名单
%w(jpg jpeg gif png)
结束
结束
以下是配置文件模型:
class Profile < ActiveRecord::Base
belongs_to :user
belongs_to :country
has_many :education_experiences
has_many :working_experiences
after_create :set_avatar_url
validates :linkedin_url, format: { with: URI.regexp }, if: Proc.new { |company| company.linkedin_url.present? }
validates :facebook_url, format: { with: URI.regexp }, if: Proc.new { |company| company.facebook_url.present? }
validates :twitter_url, format: { with: URI.regexp }, if: Proc.new { |company| company.twitter_url.present? }
validates :google_plus_url, format: { with: URI.regexp }, if: Proc.new { |company| company.google_plus_url.present? }
mount_uploader :avatar_url,ImageUploader
def set_avatar_url
avatar_url if avatar_url.present?
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
gravatar_url = "http://gravatar.com/avatar/#{gravatar_id}.png?s=100"
self.update avatar_url: gravatar_url
end
def as_json(options={})
{
country_id: self.country_id,
job_title: self.job_title,
bio: self.bio,
linkedin_url: self.linkedin_url,
facebook_url: self.facebook_url,
twitter_url: self.twitter_url,
google_plus_url: self.google_plus_url,
avatar_url: self.avatar_url,
education_experience: self.education_experiences,
working_experience: self.working_experiences
}
end
end
类配置文件
安装gem后,您可能需要重新启动服务器。似乎您没有粘贴整个堆栈跟踪。实际错误在哪里?
class Profile < ActiveRecord::Base
belongs_to :user
belongs_to :country
has_many :education_experiences
has_many :working_experiences
after_create :set_avatar_url
validates :linkedin_url, format: { with: URI.regexp }, if: Proc.new { |company| company.linkedin_url.present? }
validates :facebook_url, format: { with: URI.regexp }, if: Proc.new { |company| company.facebook_url.present? }
validates :twitter_url, format: { with: URI.regexp }, if: Proc.new { |company| company.twitter_url.present? }
validates :google_plus_url, format: { with: URI.regexp }, if: Proc.new { |company| company.google_plus_url.present? }
mount_uploader :avatar_url,ImageUploader
def set_avatar_url
avatar_url if avatar_url.present?
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
gravatar_url = "http://gravatar.com/avatar/#{gravatar_id}.png?s=100"
self.update avatar_url: gravatar_url
end
def as_json(options={})
{
country_id: self.country_id,
job_title: self.job_title,
bio: self.bio,
linkedin_url: self.linkedin_url,
facebook_url: self.facebook_url,
twitter_url: self.twitter_url,
google_plus_url: self.google_plus_url,
avatar_url: self.avatar_url,
education_experience: self.education_experiences,
working_experience: self.working_experiences
}
end
end