1

I have a model with a single field with carrierwave for file upload. I searched the google group but don't find a straightforward way to add file uploads to netzke component. I will be happy with doing it in a panel view with a regular browser file upload, i don't need anything fancy.

I just saw one of the demos has a file upload, the Paging form with custom layout. I think I still need guidance how to put it into the Basepack Grid

4

1 回答 1

2

File upload field should first be added into Basepack::Form (which then can be tested independently):

class AttachmentForm < Netzke::Basepack::Form
  def configure(c)
    super
    c.model = "Attachment"
    c.items = [{xtype: :fileuploadfield, name: 'attachment'}]
  end
end

Then your grid should be configured to use this form instead of the built-in one:

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

For reference, here's also the Attachment model:

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
于 2013-01-13T00:37:49.373 回答