Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 Activeadmin资源中的空字段_Ruby On Rails 4_Activeadmin - Fatal编程技术网

Ruby on rails 4 Activeadmin资源中的空字段

Ruby on rails 4 Activeadmin资源中的空字段,ruby-on-rails-4,activeadmin,Ruby On Rails 4,Activeadmin,我正在我的项目中使用gem'activeadmin'。 这里是app\admin\person.rb文件 ActiveAdmin.register Person do permit_params :name, :gender, :age, :address show do attributes_table do row :image do image_tag(person.image.url) end row :name

我正在我的项目中使用
gem'activeadmin'
。 这里是
app\admin\person.rb
文件

ActiveAdmin.register Person do

  permit_params :name, :gender, :age, :address
  show do
    attributes_table do
      row :image do
        image_tag(person.image.url)
      end
      row :name
      row :gender
      row :age
      row :address
    end
  end
end
如何停止在Activeadmin资源视图中显示空字段。这是一个视图的图像。 返回一个对象,如果对象为空,则返回nil。尝试:

ActiveAdmin.register Person do

  permit_params :name, :gender, :age, :address
  show do
    attributes_table do
      row :image { image_tag(person.image.url) }
      row(:name).presence
      row(:gender).presence
      row(:age).presence
      row(:address).presence
    end
  end
end

您可以在对象上使用
if语句
。 在
app\admin\person.rb
文件中

ActiveAdmin.register Person do

  permit_params :name, :gender, :age, :address, :image
  show do
    attributes_table do
      row :image if offender.image? do
        image_tag(person.image.url)
      end
      row(:name) if person.name?
      row(:gender) if person.gender?
      row(:age) if person.age?
      row(:address) if person.address?
    end
  end
end