我有一个带有carrierwave的单个字段的模型用于文件上传。我搜索了谷歌群组,但没有找到一种直接的方法来将文件上传添加到netzke组件。我会很高兴在面板视图中进行常规浏览器文件上传,我不需要任何花哨的东西。
我刚看到其中一个演示文件已上传,Paging表单带有自定义布局。我想我还需要指导如何将它放入Basepack Grid
答案 0 :(得分:2)
首先应将文件上传字段添加到Basepack::Form
(然后可以单独测试):
class AttachmentForm < Netzke::Basepack::Form
def configure(c)
super
c.model = "Attachment"
c.items = [{xtype: :fileuploadfield, name: 'attachment'}]
end
end
然后您的网格应配置为使用此表单而不是内置表单:
class AttachmentGrid < Netzke::Basepack::Grid
def configure(c)
super
c.model = 'Attachment'
c.force_fit = true
c.columns = [:link]
c.bbar = [:add_in_form, :del]
end
def preconfigure_record_window(c)
super
c.form_config.klass = AttachmentForm
c.width = 600
c.height = 150
end
end
作为参考,这里也是Attachment
模型:
class Attachment < ActiveRecord::Base
mount_uploader :attachment
# this is a virtual column referred to from `AttachmentGrid`;
# can be moved over to grid itself using `getter` in case
# you object putting HTML into the model
def link
"<a href='#{attachment.url}' target='_blank'>#{attachment.file.try(:identifier)}</a>"
end
end