Skip to content

Instantly share code, notes, and snippets.

@kimenye
Created November 18, 2013 15:25
Show Gist options
  • Save kimenye/7529599 to your computer and use it in GitHub Desktop.
Save kimenye/7529599 to your computer and use it in GitHub Desktop.
RailsAdmin.config do |config|
config.actions do
dashboard
index
new
show
edit
delete
collection :upload_renewals do
register_instance_option :link_icon do
'icon-upload'
end
register_instance_option :visible? do
bindings[:abstract_model].to_s == "Renewal"
end
register_instance_option :http_methods do
[:get, :post]
end
register_instance_option :pjax? do
false
end
register_instance_option :controller do
Proc.new do
if params.has_key?(:import_file)
doc = SimpleXlsxReader.open(params[:import_file].tempfile)
main_sheet = doc.sheets.first
count = 0
main_sheet.rows[1..main_sheet.rows.length].each do |row|
count += 1
end
redirect_to back_or_index, notice: "#{count} Rows imported"
end
end
end
end
end
end
%form.form-horizontal.denser{:method => "POST", :enctype => "multipart/form-data" }
%input{:name => "authenticity_token", :type => "hidden", :value => form_authenticity_token}
%fieldset
.control-group
%label.control-label{:for => "import_file"}
Import File
.controls
%input{:type => "file", :name => "import_file"}
%p.help-block
Select the .xls file to be imported
.form-actions
%button.btn.btn-primary{:type => "submit"}
Upload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment