randym / activeadmin-axlsx Goto Github PK
View Code? Open in Web Editor NEWActiveAdmin plugin using Axlsx for adding Excel (xlsx) download links for your resources
License: MIT License
ActiveAdmin plugin using Axlsx for adding Excel (xlsx) download links for your resources
License: MIT License
i like to download for each index or show page
here in my code look like
collection_action :download_xlsx, method: :get do
project = Project.find(params[:id])
send_data(filename: "#{project.project_name}.xlsx", type: "application/xlsx")
end
index do
column 'Download Links' do |c|
link_to 'Download', download_xlsx_admin_projects_path(id: c.id, format: :xlsx)
end
end
issue resolved. sorry
I have axlsx-3.0.0.pre.gem installed yet I continue to receive missing dependency error while attempting to install activeadmin-axlsx-2.1.2.gem
ERROR: Could not find a valid gem 'axlsx' (<=0) in any repository
Unfortunately I cannot paste any sort of screen shot, I hope this is enough information.
lib/active_admin/axlsx/resource_controller_extension.rb
index_without_xlsx(options) fails with:
wrong number of arguments (1 for 0)
def index_with_xlsx(options={}, &block)
index_without_xlsx(options) do |format|
format.xlsx do
xlsx = active_admin_config.xlsx_builder.serialize(collection)
send_data xlsx.to_stream.read, :filename => "#{xlsx_filename}", :type => Mime::Type.lookup_by_extension(:xlsx)
end
end
All my active admin index pages fail with the same error
I have used activeadmin-axslx for excel download in active admin rails 4.
When I use the filters to fetch only few records based on some condition and try to download the excel with this fetched data, the excel shows all the data irrespective of the filters.
I only need that data in the excel that I have filtered.
Can any body help me achieve this?
Thanks in advance!
I have issue to precompile assets with axlsx active admin gem, without having it in gem everything works fine
i do have meta_search and inherited_resources in gemfile
rake aborted!
uninitialized constant InheritedResources::Base
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activeadmin-0.6.0/lib/active_admin/base_controller/authorization.rb:21:in `<module:ActiveAdmin>'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activeadmin-0.6.0/lib/active_admin/base_controller/authorization.rb:1:in `<top (required)>'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activeadmin-0.6.0/lib/active_admin/base_controller.rb:3:in `<top (required)>'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activeadmin-0.6.0/lib/active_admin/resource_controller/actions.rb:2:in `<module:ActiveAdmin>'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activeadmin-0.6.0/lib/active_admin/resource_controller/actions.rb:1:in `<top (required)>'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activeadmin-0.6.0/lib/active_admin/resource_controller.rb:2:in `<top (required)>'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activeadmin-axlsx-2.1.2/lib/active_admin/axlsx.rb:21:in `block in <class:Railtie>'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.5/lib/active_support/lazy_load_hooks.rb:34:in `call'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.5/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.5/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.5/lib/active_support/lazy_load_hooks.rb:42:in `each'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.5/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.5/lib/rails/application/bootstrap.rb:69:in `block in <module:Bootstrap>'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.5/lib/rails/initializable.rb:30:in `instance_exec'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.5/lib/rails/initializable.rb:30:in `run'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.5/lib/rails/initializable.rb:54:in `each'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.5/lib/rails/initializable.rb:54:in `run_initializers'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.5/lib/rails/application.rb:136:in `initialize!'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.5/lib/sprockets/assets.rake:95:in `block (2 levels) in <top (required)>'
Tasks: TOP => assets:clean:all => assets:environment
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/home/martin/.rvm/rubies/ruby-1.9.3-p392/b...]
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.5/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.5/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/home/martin/.rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.5/lib/sprockets/assets.rake:80:in `block (2 levels) in <top (required)>'
/home/martin/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
/home/martin/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => assets:clean
(See full trace by running task with --trace)
I'm trying to get the gem working with current AA master, 1.0.0.pre and after I made a few tiny fixes I got my Rails project booted. But ActiveAdmin resources that use xlsx DSL produces this error:
undefined method `xlsx' for #<ActiveAdmin::ResourceDSL:0x007fc4e3294e10> (NoMethodError)
And my patch is https://github.com/stripeskr/activeadmin-axlsx/commit/59ea1ff5631c3f277125e4f0115d1b357f7f3bcb
Not sure if it is happening because any recent change of AA, but I can't figure it out. Can anybody help me solving it?
Hi!
Thanks for usefull gem and your work.
I have some strange problem with gem. I install it, it work. I customize xlsx for own needs and it work without problem when application run in devel mode. But if stop application and try to start it: i get such error:
app/admin/orders.rb:55:in `block in <top (required)>': undefined method `xlsx' for # <ActiveAdmin::ResourceDSL:0x007fca01d1fdd0> (NoMethodError)
gems/activeadmin-0.5.1/lib/active_admin/dsl.rb:16:in `instance_eval'
gems/activeadmin-0.5.1/lib/active_admin/dsl.rb:16:in `run_registration_block'
gems/activeadmin-0.5.1/lib/active_admin/namespace.rb:175:in `parse_registration_block'
Any idea how fix it?
rails (3.2.12), activeadmin (0.5.1), activeadmin-axlsx (2.0.0)
Hi,
In my gem file
gem 'activeadmin'
gem 'activeadmin-axlsx'
When I run bundle install, all the required gems got installed. But when I start the run "rails s" I am getting below error.
/home/rails/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.3/lib/bundler/runtime.rb:74:in require': cannot load such file -- activeadmin/axlsx (LoadError) from /home/user1/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.3/lib/bundler/runtime.rb:74:in
rescue in block in require'
from /home/user1/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.3/lib/bundler/runtime.rb:62:in block in require' from /home/user1/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in
each'
from /home/user1/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in require' from /home/user1/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.3/lib/bundler.rb:119:in
require'
from /home/user1/Workspace/audit_management/with_admin/audit/config/application.rb:7:in <top (required)>' from /home/user1/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.13/lib/rails/commands.rb:53:in
require'
from /home/user1/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.13/lib/rails/commands.rb:53:in block in <top (required)>' from /home/user1/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.13/lib/rails/commands.rb:50:in
tap'
from /home/user1/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.13/lib/rails/commands.rb:50:in <top (required)>' from script/rails:6:in
require'
from script/rails:6:in `
Can any one help me on this?
to
s.add_runtime_dependency 'activeadmin', ">= 0.6.0"
Hi,
this is me reaching out if someone else has the issue that the filter is not respected anymore, meaning all the records of the resource end up in the excel file. For the life of me I can't tie it to any change in our application, neither to an upgrade of this extension or activeadmin itself. Also it doesn't matter if a custom configuration is in play or not. Furthermore I couldn't find any indicator that the behaviour I suddenly seem to be missing was supported in the first place, but I am pretty sure it was! :) So yeah, pretty lame error report from my side. Just wondering if someone has similar troubles or can point in the right direction for further research.
Thanks, much appreciated.
Hi,
i was wondering if it would be possible to add some sort of
column_replace(:column_name { |resource| some_helper_function(resource.title) } )
to replace the value of a column.
this would be extremely helpful if one only wants to 'mangle' a few columns.
This way one wouldn't have to do all columns manually.
I got a register_page Dashboard:
ActiveAdmin.register_page "Dashboard" do
content :title => proc{ I18n.t("active_admin.dashboard") } do
columns do
column do
panel "ๆ่ฟ่ฟๆฅ็่ฎขๅ" do
table_for Order.order('id desc').limit(10) do
column("็ถๆ") { |order| status_tag t('models.order.state.' + order.state), order_state(order) }
...
end
end
end
end
end
end
The order_state
is a custom helper in app/helpers/orders_helper.rb
. It would not work after I added this gem to Gemfile. I checked the activeadmin
repo and found it's use method_missing
to find a helper, but It just can't find out the helper from @helpers
in pry debugging. More seriously, it cause infinit loop, which means the server stucked and cpu/memory is in high usage.
I tried t o configure xlsx format with code:
xlsx do
column :id
end
But got an error:
uninitialized constant ActiveAdmin::Axlsx::DSL::XlsxBuilder
I tried restarting server and oops I got another error:
undefined method `xlsx' for #ActiveAdmin::ResourceDSL:0xafaef38 (NoMethodError)
Thanks.
It seems that the gem is not compatible with active_admin 1.0.0 yet, while it is required if using rails 4.1. :(
when i do this:
column(:attending) { |resource| proc { _yesno(resource.attending) } }
where _yesno() is a helper function in the ApplicationHelper module:
def _yesno(object)
case object
when nil
""
when true
"Yes"
when false
"No"
end
end
i get the following output:
if i don't use proc {} it doesn't seem to find _yesno() which is defined in applicationHelper and
in the active_admin initializer i do:
module ActiveAdmin::ViewsHelpers
include ApplicationHelper
end
any idea?
I'm seeing an issue where repeated exports results in XLSX sheets with all rows and headers repeated several times (the number of repetitions being equal to the number of times the export is run).
The cause of the problem seems to be that the ActiveAdmin::Axlsx::Builder
provided by ActiveAdmin::Axlsx::ResourceExtension
is shared across requests. For each request, the serialize
method of the builder simply adds more rows to the existing sheet and returns it.
First of all, I would like to provide a test case for the bug. It wasn't obvious to be where to put it. What would you advice? My first hunch was to add a test case to resource_controller_spec.rb
, and simply parse the response, but perhaps you have a better idea.
Secondly, I have a crude fix:
--- a/lib/active_admin/axlsx/resource_extension.rb
+++ b/lib/active_admin/axlsx/resource_extension.rb
@@ -2,11 +2,11 @@ module ActiveAdmin
module Axlsx
module ResourceExtension
def xlsx_builder=(builder)
- @xlsx_builder = builder
+ @configured_xlsx_builder = builder
end
def xlsx_builder
- @xlsx_builder ||= ActiveAdmin::Axlsx::Builder.new(resource_class)
+ @configured_xlsx_builder || ActiveAdmin::Axlsx::Builder.new(resource_class)
end
This makes sure that every request gets a fresh builder, but it doesn't do so for a custom builder. What are your thoughts on this?
I'd be happy to submit a pull request pending your feedback.
It would be great if your gem supports the same syntax as ActiveRecord use for CSV format definition http://activeadmin.info/docs/4-csv-format.html
Hi! I couldn't find it anywhere, is there a way to export all records without pagination getting involved? E.g. I'm in the active admin index view of Users and when i export as xlsx only the current page is exported. How can i export ALL records?
first download it from github to change something.
git clone https://github.com/randym/activeadmin-axlsx
git clone https://github.com/ywencn/active_admin
make path correct.
gem 'activeadmin-axlsx', path: '../activeadmin-axlsx'
gem 'activeadmin', path: '../activeadmin'
change all below:
for undefined method `xlsx' for #ActiveAdmin::ResourceDSL:0x (NoMethodError)
yourproject/config/environments/production.rb
set
config.eager_load = false
for `require': cannot load such file -- activeadmin/axlsx (LoadError)
activeadmin-axlsx/activeadmin-axlsx.gemspec
s.add_runtime_dependency 'activeadmin', "~> 0.6.0"
to
s.add_runtime_dependency 'activeadmin', "> 0.6.0"
for ArgumentError (wrong number of arguments (1 for 0)):
activeadmin/lib/active_admin/resource_controller/streaming.rb:11:in `index'
Change line 11
def index
to
def index(arg=nil)
for undefined local variable or method max_csv_records': activeadmin-axlsx/lib/active_admin/axlsx/resource_controller_extension.rb:11:in
per_page_with_xlsx'
add max_csv_records = 1000 # some num which result in db query as limit 1000 in the end of select * query.
def per_page_with_xlsx
max_csv_records = 1000 #add
if request.format == Mime::Type.lookup_by_extension(:xlsx)
return max_csv_records
end
per_page_without_xlsx
end
I got this method (device_error_messages) in other views but the edit profile view is the only one that makes the error.
First error:
undefined method
devise_error_messages!' for #<#Class:0x007f981c25bf50:0x005556aef0e290>`
app/views/my_profiles/edit.html.slim
.row
.small-12.large-8.large-offset-2.columns
h2.section-title.text-center.section-title--margin = t('.edit_profile')
= simple_form_for user, url: my_profile_path(id: user), wrapper: :vertical_form do |f|
- if user.traveler_type.nil? or user.traveler_type.blank?
.panel.warning-message
p = t('.fill_traveler_type_field')
.panel
= devise_error_messages!
h3.sub-section-title = t('.general')
= f.input :email, label: t('.email_label')
= f.input :password, input_html: { autocomplete: "off" }, label: t('.password_label')
= f.input :name, label: t('.name_label')
= f.input :age, label: t('.age_label')
= f.input :traveler_type, collection: user.available_traveler_type_options, label: t('.traveler_type_label')
.panel
.sub-section-title = t('.notifications')
= f.input :receive_push, input_html: {class: 'push_checkbox'}, label: t('.mobile_notifications')
= f.input :receive_email_notifications, input_html: {class: 'push_checkbox'}, label: t('.email_notifications')
= f.input :urban_airship_platform, disabled: true, as: :hidden
= f.input :urban_airship_channel_id, disabled: true, as: :hidden
.panel
.sub-section-title = t('.sncf')
= f.input :sncf_card_type, collection: user.available_sncf_card_types, label: t('.sncf_card_type_label')
= f.input :sncf_fidelity_card_type, collection: user.available_sncf_fidelity_card_types, label: t('.sncf_fidelity_card_type_label')
= f.input :sncf_fidelity_card_code, label: t('.sncf_fidelity_card_code_label')
.panel
.actions
= f.button :submit, t('shared.actions.update'), class: 'button tiny expand no-margin'
What I've tried and didn't make any difference:
Second Error, happens when I try to export the users table to xls,
other tables are exported fine
undefined method
to_i' for #`
app/admin/user.rb
ActiveAdmin.register User do
actions :index, :show, :destroy, :edit, :update
permit_params :email, :admin
index do
selectable_column
column :email
column :registration_platform
column :admin
column :confirmed_at
actions
end
form do |f|
f.semantic_errors
f.inputs :email, :admin
f.actions
end
filter :email
filter :admin
end
Maybe those errors are related.
By adding the gem to my project with Rails 3.2.13 and activeadmin 0.6.2 all my routes breaks. They only way to put the routes back on track is by changing a file on my rails project so they're loaded again and everything works.
When using a "scoped_collection" to limit the columns returned in an activerecord query you will get the error "ActiveModel::MissingAttributeError".
This allows users to overwrite the default behaviour of an attribute without needing to first remove the column and then add it in with a proc.
Is there a configuration option which we can use to ensure that the trailing zeros will be stored in the xlsx file ?
My database field is a string field.
my code:
after_filter { |sheet|
new_sheet = sheet.workbook.add_worksheet(:name => 'Pivot Table')
new_sheet.add_pivot_table "A1:B2", "'Sheet1'!A1:M15" do |pivot_table|
pivot_table.rows = ['Month', 'Year']
pivot_table.columns = ['Type']
pivot_table.data = ['Sales']
end
}
but i receive
undefined method `row' for nil:NilClass
do i miss something or is this a bug?
Any chance we can get access to the collection object in the DSL vs rebuilding the query via model as shown? Params don't appear to be available in the DSL so rebuilding the users query will be kind of a pain.
Maybe something like this?
lib/active_admin/axlsx/builder.rb
def sheet_collection
@sheet_collection
end
def sheet_collection=(collection)
@sheet_collection = collection
end
def serialize(collection)
self.sheet_collection = collection
apply_filter @before_filter
export_collection(collection)
apply_filter @after_filter
to_stream
end
Hi,
First of all, thanks for this gem. It has saved hours of my time.
After installing gem 'activeadmin-axlsx'
to my Rails project, I have two issues.
I already explained that the gem seems to prevent helpers being included in controllers in #14.
The other issue that I found today is bin/compass watch
was not running properly and produced an error:
$ bin/compass compile
NameError on line ["21"] of /Users/shpark/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/lib/active_admin/base_controller/authorization.rb: uninitialized constant InheritedResources::Base
Run with --trace to see the full backtrace
I'm not sure why this is happening but removing the gem from Gemfile simply solves the problem. Running bundle exec compass watch
results the same.
Any help?
In my Gemfile where I have
gem 'activeadmin', github: 'gregbell/active_admin'
I added
gem 'activeadmin-axlsx', github: 'randym/activeadmin-axlsx'
but at
bundle install
I receive
Bundler could not find compatible versions for gem "activeadmin":
In snapshot (Gemfile.lock):
activeadmin (1.0.0.pre)
In Gemfile:
activeadmin-axlsx (>= 0) x86-mingw32 depends on
activeadmin (~> 0.6.0) x86-mingw32
Running `bundle update` will rebuild your snapshot from scratch,
using only the gems in your Gemfile, which may resolve the conflict.
Is actual master branch really incompatible with activeadmin master/pre branch or only Gemfile need fix?
Hi,
It'd be great if the header row can be omitted by configuration. For example, setting true/false to config.xlsx_builder.output_header.
At the moment disabling header seems not possible so I simply add an after_filter
to the xslx block:
after_filter do |sheet|
sheet.rows.delete_at 0
end
undefined method `fa_icon' errors when the gem is installed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.