加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails:活动管理员关联图像列

发布时间:2020-12-16 19:20:55 所属栏目:百科 来源:网络整理
导读:我是 ruby on rails的新手,刚刚安装了活动管理员,并试图自定义 观点. 我有一个产品和图像表.每个图像属于一个产品. 现在,我想在显示产品页面时显示包含相关图像的列. 目前只有image_url文本不起作用.后来我想做 将图片显示为50x50px. 我该怎么做? (图片模型
我是 ruby on rails的新手,刚刚安装了活动管理员,并试图自定义

观点.

我有一个产品和图像表.每个图像属于一个产品.

现在,我想在显示产品页面时显示包含相关图像的列.

目前只有image_url文本不起作用.后来我想做

将图片显示为50x50px.

我该怎么做? (图片模型:name:string image_url:text)

这是我做的:

ActiveAdmin.register Product do

index do
    column "Image" do |image|
        image.image_url
    end
    column :name
    column :preview_text
    column :full_text
    column :price,:sortable => :price do |product|
      div :class => "price" do
          number_to_currency product.price
     end
    end
 default_actions
 end
end

我不知道怎么用“做图像来修复那个部分.我是rails 2天exp的初学者..

似乎语法错误并抛出错误:

undefined method `image_url' for #<Product:0x00000101b5a458>

谢谢

解决方法

您需要从图像对象product.image.image_url获取image_url.

关于图像尺寸,您可以显示所需尺寸的图像,如下所示

column "Image" do |product|
  image_tag product.image.image_url,class: 'my_image_size'
end

的CSS

.my_image_size {
  width: 50px;
  height: 50px;
}

或者您可以使用诸如CarrierWave之类的宝石来实际调整图像本身的大小.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读