我有2个模型Tool::Cvt::RemoteFocu
和Tool::Cvt::RemoteFocuLog
Tool::Cvt::RemoteFocu
has_many Tool::Cvt::RemoteFocuLog
并且每个Tool::Cvt::RemoteFocuLog
都有一个snapshot
用于显示图片(由回形针处理)
我想在Tool::Cvt::RemoteFocu
中显示快照,但我得到了未定义的方法错误。
undefined method `snapshot' for nil:NilClass
但实际上Tool::Cvt::RemoteFocuLog
中的每条记录都有snapshot
方法。
ActiveAdmin.register Tool::Cvt::RemoteFocu do
f.inputs "Remote focus images" do
f.has_many :remote_focu_logs do |p|
p.input :snapshot, :as => :file, :label => "Image",:hint => p.object.snapshot.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.snapshot.url(:small))
p.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove image'
end
end
ActiveAdmin.register Tool::Cvt::RemoteFocuLog do
~~~~
答案 0 :(得分:-1)
尝试使用:hint => p.object.try(:snapshot).nil?
代替:hint => p.object.snapshot.nil?