如何编写条件 ruby 代码以 .arb 文件的形式显示(Active Admin)
How to write conditional ruby code to show in form of .arb file (Active Admin)
我想根据条件 (if..else) 获取附件模型的属性名称 (pdf_file.file_name)。但我不熟悉 Arbe Syntex,无法在视图中显示输出。
我正在渲染 active_admin
class 的部分文件。
我的 _test.arb
文件中的代码
f.has_many :course_pdf_attachments, allow_destroy: true do |attachment|
if attachment.object.pdf_file.present?
'Uploaded PDF:'
link_to attachment.object.pdf_file.filename.upcase,
attachment.object.pdf_file_url
end
attachment.input :pdf_file, as: :file
end
我在视图中得到的输出只是 input_filed
而不是我试图在条件中显示的值。
如何编写此代码以便我的值在视图中可见?
提前致谢
我过去也被这个咬过。 link_to
是一个 rails 视图助手,在 arbres
输出捕获中使用它效果不佳,除非你将它包含在一个跨度中,如下所示:
span do
link_to ...
end
另一种更像 arbre 的方法是拼出 a
标签并说:
if attachment.object.pdf_file.present?
span { 'Uploaded PDF:' }
a(href: attachment.object.pdf_file_url) do
attachment.object.pdf_file.filename.upcase
end
end
如果有效请告诉我。
我想根据条件 (if..else) 获取附件模型的属性名称 (pdf_file.file_name)。但我不熟悉 Arbe Syntex,无法在视图中显示输出。
我正在渲染 active_admin
class 的部分文件。
我的 _test.arb
文件中的代码
f.has_many :course_pdf_attachments, allow_destroy: true do |attachment|
if attachment.object.pdf_file.present?
'Uploaded PDF:'
link_to attachment.object.pdf_file.filename.upcase,
attachment.object.pdf_file_url
end
attachment.input :pdf_file, as: :file
end
我在视图中得到的输出只是 input_filed
而不是我试图在条件中显示的值。
如何编写此代码以便我的值在视图中可见?
提前致谢
我过去也被这个咬过。 link_to
是一个 rails 视图助手,在 arbres
输出捕获中使用它效果不佳,除非你将它包含在一个跨度中,如下所示:
span do
link_to ...
end
另一种更像 arbre 的方法是拼出 a
标签并说:
if attachment.object.pdf_file.present?
span { 'Uploaded PDF:' }
a(href: attachment.object.pdf_file_url) do
attachment.object.pdf_file.filename.upcase
end
end
如果有效请告诉我。