Ruby on rails Rails Carrierwave Imagemagik-指定尺寸
我正在尝试使用Rails 4制作一个应用程序。我使用carrierwave和mini_magick来处理图像 我创建了一个名为:avatar_uploader.rb的文件,其内容如下:Ruby on rails Rails Carrierwave Imagemagik-指定尺寸,ruby-on-rails,carrierwave,minimagick,Ruby On Rails,Carrierwave,Minimagick,我正在尝试使用Rails 4制作一个应用程序。我使用carrierwave和mini_magick来处理图像 我创建了一个名为:avatar_uploader.rb的文件,其内容如下: process :resize_to_fit => [800, 800] # Create different versions of your uploaded files: version :thumb do process :resize_to_fill => [200,
process :resize_to_fit => [800, 800]
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fill => [200,200]
end
version :profile do
process :resize_to_fill => [345,245]
end
version :wider do
process :resize_to_fill => [951,245]
end
version :small do
process :resize_to_fill => [35,35]
end
名为:small的版本最初名为:logo。然而,我想在一些模型上使用它的属性称为:logo,所以当我想使用这个版本时,我在行中有.logo.logo
然而,我发布了这个问题和答案(标题为琐事-第2点)建议不要连续两次使用同一个单词<代码>http://stackoverflow.com/questions/32916133/rails-how-to-show-attribute-of-an-associated-model
这就是为什么我将avatar_uploader.rb中的版本名称改为small
但是,现在当我尝试呈现show页面时:作为
<%= link_to university_path(@profile.university) do %>
<%= image_tag(@profile.university.try(:logo).small) %>
<%= @profile.university.name %>
名称显示正确,图像显示为带有问号的框。我在代码的其他部分使用了相同的图像,但版本大小不同,并且工作正常
是否需要执行某些操作来刷新化身上传器内容?在您的university.rb文件中,您应该有一行
mount_uploader:logo,AvatarUploader
您应该有一个名为logo的属性,它是模型中的一个字符串
我假设这种模式被称为大学。然后在你的图像标签中,你需要做的就是
image\u tag@profile.university.logo.small.url
你能在显示页面中显示你调用图片的代码吗?您是否向模型中添加了mount\u uploader
?模型中图片属性的名称是什么?在universions表中,我有一个名为:logo的属性我已经安装了上传器。我试着按照你的建议删除括号和“try”并添加“.url”-它不起作用-我得到了相同的错误你能通过制作一所大学的实例然后调用@university.logo.small.url来获得图片吗?你能发布更多的代码吗?
NoMethodError at /profiles/3
undefined method `small' for nil:NilClass