undefined method `slice!' for #<Hash:0x46137b8>

470 views
Skip to first unread message

karthik chigurupati

unread,
Nov 6, 2008, 6:57:05 AM11/6/08
to Ruby Reports
Greg,

I am experiencing this same error "undefined method `slice!' for
#<Hash:0x46137b8>". I am new to ruports.I Used ruby 1.8.6 and rails
1.2.6
its my first report i am not able to work my way out. I even
updated to rails 2.1.2 and experienced the same problem.



controller method
-------------------------------
def show_report
table = Site.report_table(:all,
:only => %w[site_number site_name site_region
site_on_air_date site_address site_phone_number],
:conditions => ["site_number = ?" , params[:site_number]],
:group => "site_number")

grouping = Grouping(table, :by => "site_number")


sorted_table = grouping.sort_rows_by("site_number", :order
=> :descending)

send_data sorted_table.to_pdf,
:type => "application/pdf",
:disposition => "inline",
:filename => "sites_report.pdf"
end
--------------------------------------------------------------------

view code:
---------------------------------------------------------------------
<%= link_to ("reports", :action => 'show_report', :site_number =>
@site.site_number) -%>
----------------------------------------------------------------------

Gregory Brown

unread,
Nov 6, 2008, 7:03:47 AM11/6/08
to ruby-r...@googlegroups.com
On Thu, Nov 6, 2008 at 6:57 AM, karthik chigurupati
<karthikch...@gmail.com> wrote:
>
> Greg,
>
> I am experiencing this same error "undefined method `slice!' for
> #<Hash:0x46137b8>". I am new to ruports.I Used ruby 1.8.6 and rails
> 1.2.6
> its my first report i am not able to work my way out. I even
> updated to rails 2.1.2 and experienced the same problem.

Unfortunately AAR has not been fixed and I have not found time to
investigate. This may be fixed in the Odaeus fork of Prawn, but I'm
not sure.
http://github.com/Odaeus/acts_as_reportable

-greg

--
Technical Blaag at: http://blog.majesticseacreature.com | Non-tech
stuff at: http://metametta.blogspot.com

Andrew France

unread,
Nov 6, 2008, 7:42:04 AM11/6/08
to ruby-r...@googlegroups.com
Gregory Brown wrote:
> On Thu, Nov 6, 2008 at 6:57 AM, karthik chigurupati
> <karthikch...@gmail.com> wrote:
>> Greg,
>>
>> I am experiencing this same error "undefined method `slice!' for
>> #<Hash:0x46137b8>". I am new to ruports.I Used ruby 1.8.6 and rails
>> 1.2.6
>> its my first report i am not able to work my way out. I even
>> updated to rails 2.1.2 and experienced the same problem.
>
> Unfortunately AAR has not been fixed and I have not found time to
> investigate. This may be fixed in the Odaeus fork of Prawn, but I'm
> not sure.
> http://github.com/Odaeus/acts_as_reportable

I believe Hash#slice! is a Rails 2.x method included in ActiveSupport so
it should have worked when you upgraded. My hunch is you may have
upgraded the gem but not the version lock in config/environment.rb.

Anyway, you will find that the version Gregory provided a link to
includes a patch from Marcus Derencius that allows Rails 1.x compatibility.

The easiest way to install is to just download the latest from GitHub
and extract to vendor/gems/acts_as_reportable and you may need to do
something similar to this article to load it:
http://blog.jayfields.com/2006/10/rails-autoloading-gems-in-vendor.html

Best regards,
Andrew

karthik chigurupati

unread,
Nov 7, 2008, 2:35:42 AM11/7/08
to Ruby Reports
Hello Andrew,
I have already run gem install acts_as_reportable should
i do any uninstallation before i extract
Odaeus / acts_as_reportable into my vendor folder? I cannot find Gem
folder in my vendor should i directly extract to my vendor folder?

and add-

Dir[File.dirname(__FILE__) + "/../vendor/*"].each do |path|
gem_name = File.basename(path.gsub(/-\d+.\d+.\d+$/, ''))
gem_path = path + "/lib/" + gem_name + ".rb"
require gem_path if File.exists? gem_path
end

to my envronment.rb

is it all i should do to remove slice! error?

Andrew France

unread,
Nov 7, 2008, 7:09:12 AM11/7/08
to ruby-r...@googlegroups.com
karthik chigurupati wrote:
> Hello Andrew,
> I have already run gem install acts_as_reportable should
> i do any uninstallation before i extract
> Odaeus / acts_as_reportable into my vendor folder? I cannot find Gem
> folder in my vendor should i directly extract to my vendor folder?

You shouldn't need to uninstall the original gem as the code in vendor
should take precedence.

> and add-
>
> Dir[File.dirname(__FILE__) + "/../vendor/*"].each do |path|
> gem_name = File.basename(path.gsub(/-\d+.\d+.\d+$/, ''))
> gem_path = path + "/lib/" + gem_name + ".rb"
> require gem_path if File.exists? gem_path
> end
>
> to my envronment.rb

You're right that the code on the page I provided expects it in
vendor/name_of_gem but I also noticed it checks for version numbering as
well which is a bit annoying.

I should have read that page more clearly before providing the link, I
instead suggest the one I use:
http://errtheblog.com/posts/50-vendor-everything

And is much simpler:
config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |dir|
File.directory?(lib = "#{dir}/lib") ? lib : dir
end

Just create vendor/gems/ and extract AAR into its own subdirectory. It
will then be added to Rails' load paths to be loaded automatically when
required.

>
> is it all i should do to remove slice! error?

Yes, or you can just upgrade Rails to the 2.x series.

Hope that helps,
Andrew

karthik chigurupati

unread,
Nov 7, 2008, 8:00:52 AM11/7/08
to Ruby Reports

Andrew,

Thank you so much for your long patience reply. But still i am
not able to require the odeous AAR gem into my application.

MY Environment.rb
------------------------------------------------------------------------
RAILS_GEM_VERSION = '1.2.6' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default
configuration
require File.join(File.dirname(__FILE__), 'boot')



Rails::Initializer.run do |config|

config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |
dir|
File.directory?(lib = "#{dir}/lib") ? lib : dir
end

require "ruport"

end
--------------------------------------------------------------------------
if i dont add require "ruport/acts_as_reportable" i am getting
undefined local variable acts_as_reportable
if i define Odaeus/acts_as_reportable it throws n error to

how do i require this latest gem?

Regards
Karthik

Andrew France

unread,
Nov 7, 2008, 9:13:18 AM11/7/08
to ruby-r...@googlegroups.com
karthik chigurupati wrote:
> if i dont add require "ruport/acts_as_reportable" i am getting
> undefined local variable acts_as_reportable
> if i define Odaeus/acts_as_reportable it throws n error to
>
> how do i require this latest gem?

I'm sorry but I don't understand what you're saying. I've listed the
steps below but this is just a reiteration of the previous advice.

1. Click on 'download' at
http://github.com/Odaeus/acts_as_reportable/tree/master.
2. Extract the archive into vendor/gems/acts_as_reportable.
3. Add the loading script to environment.rb as you've done or if you're
having trouble with that just:
require
"#{RAILS_ROOT}/vendor/gems/acts_as_reportable/ruport/acts_as_reportable"
(on one line)

I'm afraid I cannot probably help any further. I would strongly advise
upgrading to the latest version of Rails if possible.

Regards,
Andrew

karthik chigurupati

unread,
Nov 8, 2008, 1:27:09 AM11/8/08
to Ruby Reports

Andrew,
Thank you.i added -- require "#{RAILS_ROOT}/vendor/gems/
acts_as_reportable/lib/ruport/acts_as_reportable".

directory. i got pdf report thanks again. I try to update my whole
project to 2.*
Reply all
Reply to author
Forward
0 new messages