Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rails 4 #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Gemfile.lock
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ rvm:
- 1.9.3

notifications:
irc: "irc.freenode.org#axlsx
irc: "irc.freenode.org#axlsx"

4 changes: 4 additions & 0 deletions acts_as_xlsx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'activerecord', '>= 2.3.9'
s.add_runtime_dependency 'i18n', '>= 0.4.1'

if RUBY_VERSION == "2.0.0"
s.add_development_dependency 'rake'
s.add_development_dependency 'minitest'
end
s.add_development_dependency 'rake', "0.8.7" if RUBY_VERSION == "1.9.2"
s.add_development_dependency 'rake', "~> 0.9" if ["1.9.3", "1.8.7"].include?(RUBY_VERSION)
s.add_development_dependency 'bundler'
Expand Down
8 changes: 6 additions & 2 deletions lib/acts_as_xlsx/ar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ def to_xlsx(options = {})
header_style = p.workbook.styles.add_style(header_style) unless header_style.nil?
i18n = self.xlsx_i18n == true ? 'activerecord.attributes' : i18n
sheet_name = options.delete(:name) || (i18n ? I18n.t("#{i18n}.#{table_name.underscore}") : table_name.humanize)
data = options.delete(:data) || [*find(:all, options)]
if Rails.version[0] >= '4'
data = options.delete(:data) || where(options[:where]).order(options[:order]).to_a
else
data = options.delete(:data) || [*find(:all, options)]
end
data.compact!
data.flatten!

Expand All @@ -80,7 +84,7 @@ def to_xlsx(options = {})
data.each do |r|
row_data = columns.map do |c|
if c.to_s =~ /\./
v = r; c.to_s.split('.').each { |method| v = v.send(method) }; v
v = r; c.to_s.split('.').each { |method| !v.nil? ? v = v.send(method) : v = ""; }; v
else
r.send(c)
end
Expand Down