randym / acts_as_xlsx Goto Github PK
View Code? Open in Web Editor NEWactive record mixin for axlsx
License: MIT License
active record mixin for axlsx
License: MIT License
rake db:migrate fails when there is no database created yet. For example:
class User:
class User < ActiveRecord::Base
...
acts_as_xlsx
end
and rake db:migrate shows this:
roman@roman-home:~/tgmu_rating$ rake db:migrate
rake aborted!
Could not find table 'users'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:509:in table_structure' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:396:in
columns'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:114:in block in prepare_default_proc' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in
yield'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in columns' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:208:in
columns'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:247:in column_names' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/acts_as_xlsx-1.0.6/lib/acts_as_xlsx/ar.rb:31:in
acts_as_xlsx'
/home/roman/tgmu_rating/app/models/user.rb:18:in <class:User>' /home/roman/tgmu_rating/app/models/user.rb:1:in
<top (required)>'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:423:in load' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:423:in
block in load_file'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:615:in new_constants_in' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:422:in
load_file'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:323:in require_or_load' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:462:in
load_missing_constant'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:183:in const_missing' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:226:in
const_get'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:226:in block in constantize' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in
each'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in inject' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in
constantize'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:534:in get' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:565:in
constantize'
/home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise.rb:297:in get' /home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise/mapping.rb:77:in
to'
/home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise/mapping.rb:72:in modules' /home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise/mapping.rb:89:in
routes'
/home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise/mapping.rb:156:in default_used_route' /home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise/mapping.rb:66:in
initialize'
/home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise.rb:331:in new' /home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise.rb:331:in
add_mapping'
/home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise/rails/routes.rb:221:in block in devise_for' /home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise/rails/routes.rb:220:in
each'
/home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/devise-d5e0171cb407/lib/devise/rails/routes.rb:220:in devise_for' /home/roman/tgmu_rating/config/routes.rb:12:in
block in <top (required)>'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:316:in instance_exec' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:316:in
eval_block'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:294:in draw' /home/roman/tgmu_rating/config/routes.rb:1:in
<top (required)>'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in load' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in
block in load'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in load_dependency' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in
load'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:40:in block in load_paths' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:40:in
each'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:40:in load_paths' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:16:in
reload!'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/application.rb:102:in reload_routes!' /home/roman/.rvm/gems/ruby-2.0.0-p353/bundler/gems/active_admin-f21cff30e721/lib/active_admin/application.rb:239:in
block in attach_reloader'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:387:in _run__571715648900980799__prepare__callbacks' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in
run_callbacks'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib/action_dispatch/middleware/reloader.rb:74:in prepare!' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib/action_dispatch/middleware/reloader.rb:46:in
prepare!'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/application/finisher.rb:50:in block in <module:Finisher>' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/initializable.rb:30:in
instance_exec'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/initializable.rb:30:in run' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/initializable.rb:55:in
block in run_initializers'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/initializable.rb:54:in run_initializers' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/application.rb:215:in
initialize!'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in method_missing' /home/roman/tgmu_rating/config/environment.rb:6:in
<top (required)>'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in require' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in
block in require'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in load_dependency' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in
require'
/home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/application.rb:189:in require_environment!' /home/roman/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/application.rb:249:in
block in run_tasks_blocks'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
Was fixed with that:
class User < ActiveRecord::Base
...
acts_as_xlsx if ActiveRecord::Base.connection.table_exists? 'users'
end
But I think it is not "Rails way"
I tried to create a .xlsx.axlsx template but I get this error message:
Missing template item_refs/index, application/index with {:locale=>[:fr], :formats=>[:xlsx], :handlers=>[:erb, :builder, :raw, :ruby, :slim, :jbuilder, :coffee]}
My controller is like so:
def index
@item_refs = ItemRef.filtered_by(params[:q]).order(sort_order).first(10)
respond_to do |format|
format.html
format.js
format.xlsx { render :xlsx => "index", filename: 'items.xlsx'
}
end
end
And this is my view (index.xlsx.axlsx):
ItemRef.to_xlsx package: xlsx_package
xlsx_package.workbook.worksheets.first.tap do |sheet|
sheet.add_row ["First Column", "Second", "Third"]
sheet.add_row [1, 2, 3]
sheet.add_row [' preserving whitespace']
end
Am I doing something wrong? Thanks.
Please add this link to the readme http://www.rubydoc.info/gems/acts_as_xlsx/1.0.3/ as I was skeptical about installing a gem globally just for the documentation.
I think that the documentation is short enough that it should just be in readme, would save the hassle
tested in webrick and thin server in development env. The code works (or .xlsx.axlsx template rendered) in live server deployed in nginx and unicorn but same code renders .html.erb template in local machine in dev env. running webrick or thin. Really, can't figure out the problem.
I am looking into using this gem but noticed https://github.com/randym/axlsx was updated within the last month and this has not been updated in 2 years. Is this still the correct gem for a Rails 4 developer to use?
Hi, I'm having problems when using the gem. My model has an association that accept nulls. This association has a name method, so for the ones that are not null I would like to display the name so I have:
acts_as_xlsx :columns => [ 'supplier.name' ]
Since there are entities that do not have supplier I get:
undefined method `name' for nil:NilClass
Any workarround for this?
Thanks
Enrique
Do you have plans to drop support for ActiveRecord 2.x? It's so old and not supported by the vendor.
I am asking because acts_as_xlsx is printing deprecation notices on Rails 4. I want to submit a pull request, but before I fix it by switching on ActiveRecord version, you might want to consider dropping support for 2.x.
Calling #find(:all) is deprecated. Please call #all directly instead.
Support for mixing this into ActiveAttr in addition to ActiveRecord would be awesome.
Is your gem compatible with rails 4 / ruby 2.1 and 2.0?
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.