Since you've looked at the view and the controller, I'm starting to
suspect something in your model. I'm happy to take a look at yours,
and I've attached my Custodian model below in case you want to look
through it. .
As for csv export, my apologies, I should have mentioned you'll need a
couple other pieces. First, you need the rails plugin
acts_as_csvable. Second, you need to specify the export formats in
your model. See the acts_as_csv_exportable lines in my model below:
class Custodian < ActiveRecord::Base
hobo_model # Don't put anything above this
Custodian_type = HoboFields::EnumString.for
(:employee, :contractor, :group, :other)
Status = HoboFields::EnumString.for(:active, :inactive)
fields do
name :string, :unique
custodian_type Custodian_type
last_name :string
job_title :string
network_login :string
status Status
email :email_address
hire_date :date
hire_date_estimated :boolean
departure_date :date
departure_date_estimated :boolean
notes :text
timestamps
end
# custodian properties support through other tables
has_many :alternate_names, :dependent => :destroy, :accessible =>
true
belongs_to :location
belongs_to :group
# associations with other entities
has_many :project_custodians, :dependent => :destroy
has_many :projects, :through => :project_custodians
has_many :file_sets, :dependent => :destroy, :accessible => true
# --- Default sorting --- #
set_default_order "last_name, name"
# --- Import / Export --- #
acts_as_csv_exportable :default,
[:name, :last_name, :network_login, :custodian_type, :status, :project_list, :file_set_count, :total_megabytes, :total_items]
acts_as_csv_exportable :complete,
[:name, :custodian_type, :last_name, :alternate_names_list, :job_title, :network_login, :status, :email, :hire_date, :departure_date, :notes, :project_list, :file_set_count, :total_megabytes, :total_items]
def alternate_names_list
alternate_names.try.*.name.sort.join(', ') || ""
end
def project_list
projects.try.*.name.sort.join(', ') || ""
end
def file_set_count
file_sets.count
end
def total_megabytes
file_sets.try.*.size_megabytes.inject {|sum, elt| sum + (elt ||
0)} || 0
end
def total_volume
total_megabytes * 1024 * 1024
end
def total_items
file_sets.try.*.size_items.inject {|sum, elt| sum + (elt || 0)} ||
0
end
# --- Permissions --- #
include PermissionUser
# --- Validations --- #
validates_uniqueness_of :name, :allow_nil => false
validates_uniqueness_of :email, :allow_nil => true
validates_uniqueness_of :network_login, :allow_nil => true
validates_date :hire_date, :allow_nil => true, :before =>
[:departure_date, Proc.new {1.day.from_now.to_date}]
validates_date :departure_date, :allow_nil => true, :before =>
Proc.new {1.day.from_now.to_date}, :after => :hire_date
end