我是Ruby的新手,我正在尝试在CarrierWave的方法中传递一个名为version的参数。我的想法是获得不透明度参数值,但我不知道如何编写代码,以免在ruby中出现一些语法错误。
这是没有参数不透明度的普通代码:
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::RMagick
version :big_image, :from_version => :redes_sociales do
process :resize_to_limit => [860, 860]
process adjust_quality: (85)
process :watermark => [0.39, 'g']
end
version :medium_image(opacity_value = 0.39), :from_version => :redes_sociales do
process :resize_to_limit => [536,432]
process :watermark => [0.39, 'm']
end
end
这就是我试图重写参数的方法:
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::RMagick
version :big_image(opacity_value = 0.39), :from_version => :redes_sociales do
process :resize_to_limit => [860, 860]
process adjust_quality: (85)
process :watermark => [opacity_value, 'g']
end
version :medium_image(opacity_value = 0.39), :from_version => :redes_sociales do
process :resize_to_limit => [536,432]
process :watermark => [opacity_value, 'm']
end
end
然后我可以在控制器或视图中使用:
imagen_popup = p.avatar.url(:big_image(0.8))
或:
<a href="<%= c.picture.avatar.url(:big_image(0.8)) %>"
有关如何传递参数的任何建议或想法?感谢