incompatible character encodings: ASCII-8BIT and UTF-8 - ruby-on-rails

I use Ruby 1.9.2 and Rails 3.0.5
I have the following error:
incompatible character encodings: ASCII-8BIT and UTF-8
It has nothing to do with the database i think.
The error is happinging on this line in a view (just a div haml call):
#content
full stack:
ActionView::Template::Error (incompatible character encodings: ASCII-8BIT and UTF-8):
21: -flash.each do |name, msg|
22: =content_tag :div, msg, :id => "flash_#{name}"
23: %div.clear
24: #content
25: = yield
26: = render :partial => "layouts/grid_right" if render_grid_right?
27: = render :partial => "layouts/footer"
app/views/layouts/application.html.haml:24:in `_app_views_layouts_application_html_haml___4380000789490545718_2180251300_2717546578298801795'
actionpack (3.0.5) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.5) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.5) lib/action_view/template.rb:127:in `render'
actionpack (3.0.5) lib/action_view/render/layouts.rb:80:in `_render_layout'
actionpack (3.0.5) lib/action_view/render/rendering.rb:62:in `block in _render_template'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.5) lib/action_view/render/rendering.rb:26:in `render'
haml (3.0.25) lib/haml/helpers/action_view_mods.rb:13:in `render_with_haml'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.5) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.5) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.5) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.0.5) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/michaelkoper/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
activesupport (3.0.5) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.5) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.0.5) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.0.5) lib/action_controller/metal/mime_responds.rb:261:in `block in retrieve_response_from_mimes'
actionpack (3.0.5) lib/action_controller/metal/mime_responds.rb:192:in `call'
actionpack (3.0.5) lib/action_controller/metal/mime_responds.rb:192:in `respond_to'
app/controllers/home_controller.rb:9:in `index'
actionpack (3.0.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.5) lib/active_support/callbacks.rb:445:in `_run__3968431659371141392__process_action__3163094469870857953__callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.5) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:68:in `optimized_each'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:492:in `call'
haml (3.0.25) lib/sass/plugin/rack.rb:41:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.5) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.5) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.5) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.5) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.5) lib/rails/application.rb:168:in `call'
railties (3.0.5) lib/rails/application.rb:77:in `method_missing'
railties (3.0.5) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.1) lib/rack/content_length.rb:13:in `call'
rack (1.2.1) lib/rack/chunked.rb:15:in `call'
rack (1.2.1) lib/rack/handler/mongrel.rb:67:in `process'
mongrel (1.2.0.pre2) lib/mongrel.rb:165:in `block in process_client'
mongrel (1.2.0.pre2) lib/mongrel.rb:164:in `each'
mongrel (1.2.0.pre2) lib/mongrel.rb:164:in `process_client'
mongrel (1.2.0.pre2) lib/mongrel.rb:291:in `block (2 levels) in run'
My gems:
Using rake (0.8.7)
Using RedCloth (4.2.2)
Using abstract (1.0.0)
Using activesupport (3.0.5)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.5)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.7)
Using tzinfo (0.3.24)
Using actionpack (3.0.5)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.15)
Using actionmailer (3.0.5)
Using arel (2.0.9)
Using activerecord (3.0.5)
Using activeresource (3.0.5)
Using authlogic (2.1.6)
Using xml-simple (1.0.14)
Using aws-s3 (0.6.2)
Using block_helpers (0.3.3)
Using bundler (1.0.10)
Using diff-lcs (1.1.2)
Using json (1.4.6)
Using gherkin (2.3.4)
Using term-ansicolor (1.0.5)
Using cucumber (0.10.0)
Using cucumber-rails (0.3.2)
Using daemons (1.0.10)
Using database_cleaner (0.6.5)
Using factory_girl (1.3.3)
Using faker (0.9.5)
Using formtastic (1.2.3)
Using gem_plugin (0.2.3)
Using haml (3.0.25)
Using thor (0.14.6)
Using railties (3.0.5)
Using rails (3.0.5)
Using kaminari (0.10.4)
Using mongrel (1.2.0.pre2)
Using mysql2 (0.2.6)
Using nokogiri (1.4.4)
Using paperclip (2.3.8)
Using rspec-core (2.5.1)
Using rspec-expectations (2.5.0)
Using rspec-mocks (2.5.0)
Using rspec (2.5.0)
Using yard (0.6.4)
Using pickle (0.4.4)
Using populator (1.0.0)
Using rspec-rails (2.5.0)
Using webrat (0.7.3)

I solved it by following these steps:
Make sure config.encoding = "utf-8" is in the application.rb file.
Make sure you are using the 'mysql2' gem.
Put # encoding: utf-8 at the top of file containing UTF-8 characters.
Above the <App Name>::Application.initialize! line in the environment.rb file, add following two lines:
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
http://rorguide.blogspot.com/2011/06/incompatible-character-encodings-ascii.html

Try to find the exact line which causing this problem and then enforce UTF8 coding, this solution worked for me.
title.to_s.force_encoding("UTF-8")

I have a suspicion that you either copy/pasted a part of your Haml template into the file, or you're working with a non-Unicode/non-UTF-8 friendly editor.
See if you can recreate that file from the scratch in a UTF-8 friendly editor. There are plenty for any platform and see whether this fixes your problem. Start by erasing the line with #content and retyping it manually.

ASCII-8BIT is Ruby's description for characters above the normal 0-0x7f ASCII character-set, and that are single-byte characters. Typically that would be something like ISO-8859-1, or one of its siblings.
If you can identify which character is causing the problem, then you can tell Ruby 1.9.2 to convert between the character set of that character to UTF-8.
James Grey wrote a series of blogs talking about these sort of problems and how to deal with them. I'd recommend going through them.
incompatible character encodings: ASCII-8BIT and UTF-8
That typically happens because you are trying to concatenate two strings, and one contains characters that do not map to the character-set of the other string. There are characters in ISO-8859-1 that do not have equivalents in UTF-8, and vice-versa and how to handle string joining with those incompatibilities requires the programmer to step in.

you can force UTF8 with force_encoding(Encoding::UTF_8):
Example:
<%= yield.force_encoding(Encoding::UTF_8) %>

For Haml put an encoding hint:
-# coding: UTF-8
on the top left of the Haml page.

I installed gem package mysql2.
gem install mysql2
and then I changed the adapter in mysql2 in database.yml.

The problem was the use of incorrect quotes around the iOS version. Make sure all your quotes are ' and not ‘ or ’.
https://github.com/CocoaPods/CocoaPods/issues/829

For prevent an error "can't modify frozen string" for encoding a varible you can use: var.dup.force_encoding(Encoding::ASCII_8BIT) or var.dup.force_encoding(Encoding::UTF_8)

I've experienced similar problem. Although I had have UTF-8 encodings solved (with mysql2 and Encoding.default_external = Encoding::UTF_8 ...) incompatible character encodings: UTF-8 and ASCII-8BIT arose when I used incorrect helper parameters e.g. f.button :submit, "Zrušiť" - works perfectly but f.button "Zrušiť"- throws encoding error.

I encountered the error while migrating an app from Ruby 1.8.7 to 1.9.3 and it only occured in production. It turned out that I had some leftovers in my Memcache store. The now encoding sensitive Ruby 1.9.3 version of my app tried to mix old ASCII-8BIT values with new UTF-8.
It was as simple as flushing the cache to fix it for me.

I had a similar issue on a custom CoffeeScript file. I solved it by changing the endline encoding from "Unix/Linux" to "Mac OS Classic"

The creation of pdf-documents with the rails-latex-gem lead to a similar problem.
I solved this by modifying layouts/application.pdf.erb to
\begin{document}
<%= yield.force_encoding("UTF-8") %>
\end{document}

it's very strange that I met this problem because I forgot specify the 'type' parameter. e.g.:
add_column :cms_push_msgs, :android_title
which should be:
add_column :cms_push_msgs, :android_content, :string

Just for the record: for me it turned out that it was the gem called 'mysql' ... obviously this is working with US-ASCII 8 bit by default. So changing it to the gem called mysql2 (the 2 is the important point here) solved all of my issues.
I looked # the gem list posted above - Michael Koper has obviously mysql2 installed but I posted this in case someone has this issue as well .. (took me some time to figure out).
If you dislike this answer please comment and I will delete it.
P.S: German umlauts (ä,ö and ü) screwed it out with mysql

I had the same problem when parsing CSV files on Ruby 1.9.2 that were correctly parsed on Ruby 1.8. I found the answer here. When opening the CSV file with Ruby CSV module it is necessary to specify UTF-8 enconding as following:
CSV.foreach("file.txt", encoding: "UTF-8") do |row|
# foo and bar correctly encoded
foo, bar, ... = row
end

i had a similiar problem and the gem string-scrub automagically fixed it for me. https://github.com/hsbt/string-scrub If the given string contains an invalid byte sequence then that invalid byte sequence is replaced with the unicode replacement character (�) and a new string is returned.

I got the same cryptic error message from Rails 4.1, Ruby 2.3.3 in a recent project, stacktrace originating in layout application.html.haml
After a wild goose chase, the culprit was a UTF-8 character which recently had been added to the footer of all pages. For some weird reason the error would only show up intermittently.
Replacing the UTF-8 character with the corresponding HTML escape sequence &#xHHHH; solved the issue.
I hope this saves other people some time in the future..

If the cause of the error is a render block, this works:
<%= (
render "{SOME_TEMPLATE}", some_variable: some_variable
).force_encoding("UTF-8") %>
I have split the lines to show the brackets and the force encoding

Related

'Mongo::OperationFailure' for some actions in Rails

I'm new to Mongo. I've installed Mongodb from this source. I'm using the mongodb for Rails application. The app loads fine after starting the mongodb and rails. However, it fails when I try to login. The same thing happens when I try to perform some operations in rails console.
Here the model code:
def self.authenticate(email, password)
user = find(:first, :conditions => {:email => email})
if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
user
else
nil
end
end
Its failing at if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
Here is the short error:
Database command 'create' failed: {"ok"=>0.0, "errmsg"=>"collection already exists", "code"=>48}
And, the full application error trace:
mongo (1.3.1) lib/mongo/db.rb:506:in command'
mongo (1.3.1) lib/mongo/db.rb:284:increate_collection'
mongoid (2.2.1) lib/mongoid/collections/master.rb:41:in initialize'
mongoid (2.2.1) lib/mongoid/collection.rb:127:innew'
mongoid (2.2.1) lib/mongoid/collection.rb:127:in master'
mongoid (2.2.1) lib/mongoid/collection.rb:60:infind_one'
mongoid (2.2.1) lib/mongoid/contexts/mongo.rb:164:in first'
mongoid (2.2.1) lib/mongoid/criteria.rb:42:inone'
mongoid (2.2.1) lib/mongoid/criterion/inclusion.rb:104:in find'
mongoid (2.2.1) lib/mongoid/finders.rb:83:infind'
actionpack (3.0.3) lib/action_controller/metal/implicit_render.rb:4:in send_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:151:inprocess_action'
actionpack (3.0.3) lib/action_controller/metal/rendering.rb:11:in process_action'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:18:inblock in process_action'
activesupport (3.0.3) lib/active_support/callbacks.rb:435:in _run__902337259577170033__process_action__4476240526817474042__callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:409:in_run_process_action_callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in run_callbacks'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:17:inprocess_action'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:30:in block in process_action'
activesupport (3.0.3) lib/active_support/notifications.rb:52:inblock in instrument'
activesupport (3.0.3) lib/active_support/notifications/instrumenter.rb:21:in instrument'
activesupport (3.0.3) lib/active_support/notifications.rb:52:ininstrument'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:29:in process_action'
actionpack (3.0.3) lib/action_controller/metal/rescue.rb:17:inprocess_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:120:in process'
actionpack (3.0.3) lib/abstract_controller/rendering.rb:40:inprocess'
actionpack (3.0.3) lib/action_controller/metal.rb:138:in dispatch'
actionpack (3.0.3) lib/action_controller/metal/rack_delegation.rb:14:indispatch'
actionpack (3.0.3) lib/action_controller/metal.rb:178:in block in action'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:incall'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in dispatch'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:27:incall'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:inblock in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:75:in optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:inrecognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in call'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:492:incall'
mongoid (2.2.1) lib/rack/mongoid/middleware/identity_map.rb:33:in block in call'
mongoid (2.2.1) lib/mongoid.rb:130:inunit_of_work'
mongoid (2.2.1) lib/rack/mongoid/middleware/identity_map.rb:33:in call'
actionpack (3.0.3) lib/action_dispatch/middleware/best_standards_support.rb:17:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/head.rb:14:in call'
rack (1.2.4) lib/rack/methodoverride.rb:24:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/params_parser.rb:21:in call'
actionpack (3.0.3) lib/action_dispatch/middleware/flash.rb:182:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:149:in call'
actionpack (3.0.3) lib/action_dispatch/middleware/cookies.rb:295:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:46:in block in call'
activesupport (3.0.3) lib/active_support/callbacks.rb:415:in_run_call_callbacks'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:44:in call'
rack (1.2.4) lib/rack/sendfile.rb:106:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/remote_ip.rb:48:in call'
actionpack (3.0.3) lib/action_dispatch/middleware/show_exceptions.rb:46:incall'
railties (3.0.3) lib/rails/rack/logger.rb:13:in call'
rack (1.2.4) lib/rack/runtime.rb:17:incall'
activesupport (3.0.3) lib/active_support/cache/strategy/local_cache.rb:72:in call'
rack (1.2.4) lib/rack/lock.rb:11:inblock in call'
rack (1.2.4) lib/rack/lock.rb:11:in synchronize'
rack (1.2.4) lib/rack/lock.rb:11:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/static.rb:30:in call'
railties (3.0.3) lib/rails/application.rb:168:incall'
railties (3.0.3) lib/rails/application.rb:77:in method_missing'
railties (3.0.3) lib/rails/rack/log_tailer.rb:14:incall'
rack (1.2.4) lib/rack/content_length.rb:13:in call'
rack (1.2.4) lib/rack/handler/webrick.rb:52:inservice'
/Users/reonios/.rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/webrick/httpserver.rb:138:in service'
/Users/reonios/.rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/webrick/httpserver.rb:94:inrun'
/Users/reonios/.rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Any help is highly appreciated.
After checking the code and googling I found that a special character was sent in every request. My request parameters were like this:
{
"utf8"=>"✓",
"authenticity_token"=>"cAcdDOzfBgalF5em+97mTKw9DAjymfmEmG6hc+dDqhQ=",
"email"=>"super_admin_user#test.com",
"password"=>"[FILTERED]",
"commit"=>"Login"
}
Not sure what triggered 'âœ'. But one of the post in google says, there is a bug related to this present in the 2.2 series and that is got fixed with later versions.
So, I found my mongoid version to be 2.2.1 and once I had it upgraded the problem got resolved.
NOTE: Am new to mongoid and gave a solution with minimal knowledge. Please add details if needed.

Rails + JRuby: I'm getting a JDBC error while rendering the default app

I'm trying to make Rails work under a JRuby environment. I got everything working; no installation errors.
I installed Rails using jruby -S gem install rails, then I created a test app using both jruby -S rails new webtest and rails -S new webtest (second attempt). Both commands deploy the complete app directory with no errors.
Now, I haven't changed anything at all and I'm now just trying to see if the defaults work before I try anything else, so I cd webtest and run jruby -S rails server -b x.xx.xx.xx (second attempt: rails server -b x.xx.xx.xx) where the x's represent the server ip address in the internal network. The service is started and outputs the app URL, PID etc. I'm binding to the ip address because I need to access the app from another machine since the server itself is console only (if I leave the default bind [i.e. localhost], the app is unreachable for some reason).
But when I try to open the app (accessing from another machine) using http://x.xx.xx.xx:3000 I get the a Rails exception page with the header ActiveRecord::JDBCError and the following stacktrace. I tried to figure out what's wrong but, as you can see, the trace doesn't show any specific error message besides the trace.
Any help or insight is greatly appreciated.
>jruby -S rails server -b x.xx.xx.xx
NOTE: ActiveRecord 4.2 is not (yet) fully supported by AR-JDBC, please help us finish 4.2 support - check http://bit.ly/jruby-42 for starters
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://x.xx.xx.xx:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-02-27 14:28:00] INFO WEBrick 1.3.1
[2015-02-27 14:28:00] INFO ruby 1.9.3 (2013-12-06) [java]
[2015-02-27 14:28:00] INFO WEBrick::HTTPServer#start: pid=25886932 port=3000
Then while trying to access the app URL from another machine:
arjdbc/jdbc/RubyJdbcConnection.java:453:in `init_connection'
activerecord-jdbc-adapter (1.3.14) lib/arjdbc/jdbc/connection.rb:15:in `initialize'
activerecord-jdbc-adapter (1.3.14) lib/arjdbc/jdbc/adapter.rb:68:in `initialize'
activerecord-jdbc-adapter (1.3.14) lib/arjdbc/jdbc/connection_methods.rb:12:in `jdbc_connection'
activerecord-jdbc-adapter (1.3.14) lib/arjdbc/sqlite3/connection_methods.rb:24:in `sqlite3_connection'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `checkout'
/home/srpec/jruby-1.7.9/lib/ruby/1.9/monitor.rb:211:in `mon_synchronize'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `connection'
/home/srpec/jruby-1.7.9/lib/ruby/1.9/monitor.rb:211:in `mon_synchronize'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
activerecord (4.2.0) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
activerecord (4.2.0) lib/active_record/connection_handling.rb:87:in `connection'
activerecord (4.2.0) lib/active_record/migration.rb:384:in `connection'
activerecord (4.2.0) lib/active_record/migration.rb:371:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `call'
org/jruby/RubyProc.java:271:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:738:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
/home/srpec/jruby-1.7.9/lib/ruby/1.9/webrick/httpserver.rb:138:in `service'
/home/srpec/jruby-1.7.9/lib/ruby/1.9/webrick/httpserver.rb:94:in `run'
/home/srpec/jruby-1.7.9/lib/ruby/1.9/webrick/server.rb:191:in `start_thread'
Environment information:
>rails -v
Rails 4.2.0
>jruby -v
jruby 1.7.9 (1.9.3p392) 2013-12-06 87b108a on IBM J9 VM pap3270_27sr2-20141101_01 (SR2) [AIX-ppc]
>jgem list --local
*** LOCAL GEMS ***
actionmailer (4.2.0)
actionpack (4.2.0)
actionview (4.2.0)
activejob (4.2.0)
activemodel (4.2.0)
activerecord (4.2.0)
activerecord-jdbc-adapter (1.3.14)
activerecord-jdbcsqlite3-adapter (1.3.14)
activesupport (4.2.0)
arel (6.0.0)
builder (3.2.2)
bundler (1.8.3)
coffee-rails (4.1.0)
coffee-script (2.3.0)
coffee-script-source (1.9.1)
erubis (2.7.0)
execjs (2.3.0)
globalid (0.3.3)
hike (1.2.3)
i18n (0.7.0)
jbuilder (2.2.8)
jdbc-sqlite3 (3.8.7)
jquery-rails (4.0.3)
json (1.8.2 java)
loofah (2.0.1)
mail (2.6.3)
mime-types (2.4.3)
minitest (5.5.1)
multi_json (1.10.1)
nokogiri (1.6.6.2 java)
rack (1.6.0)
rack-test (0.6.3)
rails (4.2.0)
rails-deprecated_sanitizer (1.0.3)
rails-dom-testing (1.0.5)
rails-html-sanitizer (1.0.1)
railties (4.2.0)
rake (10.4.2)
rdoc (4.2.0)
sass (3.4.13)
sass-rails (5.0.1)
sdoc (0.4.1)
sprockets (2.12.3)
sprockets-rails (2.2.4)
therubyrhino (2.0.4)
therubyrhino_jar (1.7.4)
thor (0.19.1)
thread_safe (0.3.4 java)
tilt (1.4.1)
turbolinks (2.5.3)
tzinfo (1.2.2)
tzinfo-data (1.2015.1)
uglifier (2.7.0)

'Nesting too deep' error while retrieving JSON using HTTParty

I am writing a very simple proxy wrapper for the reddit api so I can make cross domain JSONP requests (reddit does not allow JSONP calls to my knowledge).
I am using the HTTParty gem to make the call out and retrieve the response, which I immediately render out as json.
I am retrieving the subreddit json perfectly fine so far with this as my route:
match "r/:name" => "api#subreddit"
... and this as my controller action:
def subreddit
render :json => HTTParty.get("http://www.reddit.com/r/" + params[:name] + "/.json"), :callback => params[:callback]
end
As an example, the JSON that comes back is similar to this: http://www.reddit.com/r/pics/.json
My problem is when I attempt to grab the comments for a particular thread.
My route is as so:
match "r/:name/comments/:id" => "api#comments"
... and my controller action is this:
def comments
render :json => HTTParty.get("http://www.reddit.com/r/" + params[:name] + "/comments/" + params[:id] + "/.json"), :callback => params[:callback]
end
The JSON that I want back can be seen here: http://www.reddit.com/r/pics/comments/rhzgc/.json
When I call this action, however, I receive the following error message:
MultiJson::DecodeError in ApiController#comments
Nesting of 20 is too deep
The full stack trace follows:
json (1.6.6) lib/json/common.rb:148:in `parse'
json (1.6.6) lib/json/common.rb:148:in `parse'
multi_json (1.2.0) lib/multi_json/engines/json_common.rb:9:in `decode'
multi_json (1.2.0) lib/multi_json.rb:81:in `decode'
httparty (0.8.1) lib/httparty/parser.rb:116:in `json'
httparty (0.8.1) lib/httparty/parser.rb:136:in `parse_supported_format'
httparty (0.8.1) lib/httparty/parser.rb:103:in `parse'
httparty (0.8.1) lib/httparty/parser.rb:66:in `call'
httparty (0.8.1) lib/httparty/request.rb:222:in `parse_response'
httparty (0.8.1) lib/httparty/request.rb:192:in `handle_response'
httparty (0.8.1) lib/httparty/request.rb:75:in `perform'
httparty (0.8.1) lib/httparty.rb:391:in `perform_request'
httparty (0.8.1) lib/httparty.rb:343:in `get'
httparty (0.8.1) lib/httparty.rb:423:in `get'
app/controllers/api_controller.rb:12:in `comments'
actionpack (3.1.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.1.1) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.1.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.1.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.1.1) lib/active_support/callbacks.rb:416:in `_run__2872109728488784816__process_action__2261783022290592822__callbacks'
activesupport (3.1.1) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
activesupport (3.1.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.1.1) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.1.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.1.1) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.1) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.1.1) lib/action_controller/metal/params_wrapper.rb:201:in `process_action'
activerecord (3.1.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.1.1) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.1.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.1.1) lib/action_controller/metal.rb:193:in `dispatch'
actionpack (3.1.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.1.1) lib/action_controller/metal.rb:236:in `block in action'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:65:in `call'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:65:in `dispatch'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:29:in `call'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:89:in `optimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:532:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.6) lib/rack/etag.rb:23:in `call'
rack (1.3.6) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/flash.rb:243:in `call'
rack (1.3.6) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.6) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/cookies.rb:331:in `call'
activerecord (3.1.1) lib/active_record/query_cache.rb:62:in `call'
activerecord (3.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.1) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.1) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.6) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.1) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.6) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.6) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.6) lib/rack/lock.rb:15:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.1) lib/rails/engine.rb:456:in `call'
railties (3.1.1) lib/rails/rack/content_length.rb:16:in `call'
railties (3.1.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.6) lib/rack/handler/webrick.rb:59:in `service'
/Users/emcummings/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/emcummings/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/emcummings/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
What am I doing wrong here? If the JSON is too big to parse (I find that sort of hard to believe!) what can I do?
EDIT:
Looks like dropping back to the standard NET::HTTP lib solved my problem:
uri = URI.parse("http://www.reddit.com/r/pics/comments/rhzgc/.json")
response = Net::HTTP.get_response(uri)
render :json => response.body, :callback => params[:callback]
#OK!
... but I still am curious why I am failing this same call with HTTParty!
Thanks for the help!
It's not that the JSON is too large. It's nested too deeply. HTTParty tries to decode the results that it gets automatically. Following your stack trace, and the HTTParty dependencies, it relies on multi_json which is using the json gem.
Inside of json there is lib/json/pure/parser.rb. The default max depth set is set in there, specifically on line 79. Something in your returned JSON is 20+ levels deep, triggering the exception.
if !opts.key?(:max_nesting) # defaults to 19
#max_nesting = 19
Switched to the OJ JSON parser by adding the following to my Gemfile:
gem 'oj'
and this issue resolved itself.
It looks like this can be worked around by calling to_json with the max_nesting option set.
json = obj.to_json(max_nesting: 50)

New Rails App Fails loading assets

I'm trying to get a brand new skeleton app running in rails 3.1.0.rc8. However, whenever any asset tag/helper is used in a view(such as image_tag, javascript_include_tag, etc.), I get a asset compile error. Here's a snippet of my logs/development.log when I make a direct request to /assets/rails.png.
Started GET "/assets/rails.png" for 192.168.0.12 at Mon Aug 29 16:16:21 -0600 2011
Error compiling asset rails.png:
ArgumentError: wrong number of arguments (2 for 1)
activesupport (3.1.0.rc8) lib/active_support/cache/file_store.rb:101:in `respond_to?'
activesupport (3.1.0.rc8) lib/active_support/cache/file_store.rb:101:in `dump'
activesupport (3.1.0.rc8) lib/active_support/cache/file_store.rb:101:in `write_entry'
activesupport (3.1.0.rc8) lib/active_support/core_ext/file/atomic.rb:20:in `atomic_write'
activesupport (3.1.0.rc8) lib/active_support/cache/file_store.rb:101:in `write_entry'
activesupport (3.1.0.rc8) lib/active_support/cache/strategy/local_cache.rb:140:in `write_entry'
activesupport (3.1.0.rc8) lib/active_support/cache.rb:364:in `write'
activesupport (3.1.0.rc8) lib/active_support/cache.rb:520:in `instrument'
activesupport (3.1.0.rc8) lib/active_support/cache.rb:362:in `write'
sprockets (2.0.0.beta.15) lib/sprockets/caching.rb:117:in `cache_set'
sprockets (2.0.0.beta.15) lib/sprockets/caching.rb:80:in `cache_set_hash'
sprockets (2.0.0.beta.15) lib/sprockets/caching.rb:51:in `cache_asset'
sprockets (2.0.0.beta.15) lib/sprockets/environment.rb:82:in `build_asset'
sprockets (2.0.0.beta.15) lib/sprockets/trail.rb:102:in `find_asset_in_path'
sprockets (2.0.0.beta.15) lib/sprockets/base.rb:102:in `find_asset'
sprockets (2.0.0.beta.15) lib/sprockets/environment.rb:72:in `find_asset'
sprockets (2.0.0.beta.15) lib/sprockets/server.rb:42:in `call'
rack-mount (0.8.2) lib/rack/mount/prefix.rb:26:in `call'
rack-mount (0.8.2) lib/rack/mount/route_set.rb:152:in `call'
rack-mount (0.8.2) lib/rack/mount/code_generation.rb:96:in `recognize'
rack-mount (0.8.2) lib/rack/mount/code_generation.rb:68:in `optimized_each'
rack-mount (0.8.2) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.2) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.0.rc8) lib/action_dispatch/routing/route_set.rb:531:in `call'
actionpack (3.1.0.rc8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.2) lib/rack/etag.rb:23:in `call'
rack (1.3.2) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.1.0.rc8) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.0.rc8) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.0.rc8) lib/action_dispatch/middleware/flash.rb:243:in `call'
rack (1.3.2) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.2) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.0.rc8) lib/action_dispatch/middleware/cookies.rb:326:in `call'
activerecord (3.1.0.rc8) lib/active_record/query_cache.rb:62:in `call'
activerecord (3.1.0.rc8) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.0.rc8) lib/action_dispatch/middleware/callbacks.rb:29:in `call'
activesupport (3.1.0.rc8) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.0.rc8) lib/active_support/callbacks.rb:81:in `send'
activesupport (3.1.0.rc8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.0.rc8) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.0.rc8) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.2) lib/rack/sendfile.rb:101:in `call'
I'm running ruby 1.8.7 and Passenger, if relevant. Anyone else running into this error?
Fixed this by upgrading from sprockets 2.0.0.beta.15 to 2.0.0:
gem install sprockets -v=2.0.0
Kudos to Ryan Bigg for the help.
I met the same problem when compiling assets via rake task:
$ bundle exec rake assets:precompile --trace
...
** Execute assets:precompile:primary
rake aborted!
wrong number of arguments (2 for 1)
/usr/local/lib/ruby/gems/1.8/gems/activesupport-3.2.0/lib/active_support/cache/file_store.rb:91:in `respond_to?'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-3.2.0/lib/active_support/cache/file_store.rb:91:in `dump'
...
after spending 4+ hours and tried many approaches, I found that it may be an issue of Ruby. ( from this link: https://github.com/resolve/refinerycms/issues/538 )
$ ruby -v
ruby 1.8.7 (2008-05-31 patchlevel 0)
Here the patchlevel 0 is the problem. since my ruby was compiled from the source code. (some reason I can't make it installed from package manager or via RVM).
Solution:
Download a new source file from http://ftp.ruby-lang.org/pub/ruby/1.8/, e.g. patch 358 ,
compile it:
unzip ruby-1.8.7-p358.zip -d /tmp && cd /tmp/ruby-1.8.7-p358 && ./configure && make && sudo make install
now ruby has a new version: patch 358
$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [i686-linux]
and everything works!

Error using ActiveResource with Rails 3 and REST API

I have a REST API that I am trying to access using Rails 3.0.1 that returns:
<Sessions>
<Session>
<Title>This is a sample title</Title>
...Misc
</Session>
<Session>
<Title>Another Title</Title>
...Misc
</Session>
</Sessions>
I have set up my session.rb class defined:
class Session < ActiveResource::Base
self.site = "http://example.com/rest"
end
The url that will return the XML is http://example.com/rest/sessions.
I then have a controller that is defined as this:
class HomeController < ApplicationController
def index
Session.all
end
end
and my view, index.html.erb, is defined:
<h1>List Sessions</h1>
<% #sessions.each do |session| %>
<div><%= session.title %></div>
<% end %>
When I try to view this page, I get the following error:
NoMethodError in HomeController#index
undefined method `collect!' for #<Hash:0x00000105178af8>
What could be causing this issue? I can access the url just fine (even using http://example.com/rest/sessions.xml). Is there a way to debug ActiveResource to see what is happening inside?
EDIT
Here is the stack trace:
activeresource (3.0.1) lib/active_resource/base.rb:885:in `instantiate_collection'
activeresource (3.0.1) lib/active_resource/base.rb:857:in `find_every'
activeresource (3.0.1) lib/active_resource/base.rb:777:in `find'
activeresource (3.0.1) lib/active_resource/base.rb:803:in `all'
app/controllers/home_controller.rb:4:in `index'
actionpack (3.0.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.1) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.1) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.1) lib/active_support/callbacks.rb:435:in `_run__140584718597918073__process_action__4423897468290757938__callbacks'
activesupport (3.0.1) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.1) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.1) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.1) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.1) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.1) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.1) lib/abstract_controller/rendering.rb:40:in `process'
actionpack (3.0.1) lib/action_controller/metal.rb:133:in `dispatch'
actionpack (3.0.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.1) lib/action_controller/metal.rb:173:in `block in action'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:68:in `optimized_each'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:492:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/cookies.rb:287:in `call'
activerecord (3.0.1) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.1) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.1) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.1) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.1) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.1) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.1) lib/rails/application.rb:168:in `call'
railties (3.0.1) lib/rails/application.rb:77:in `method_missing'
railties (3.0.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.1) lib/rack/content_length.rb:13:in `call'
rack (1.2.1) lib/rack/handler/webrick.rb:52:in `service'
/Users/swright/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/swright/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/swright/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Simple answer, if you try to session in your views it will access the Rails Session object, you have a naming problem on your hands.
Thats why the Hash error is coming, it tries to access the session Hash.
Try something like
<h1>List Sessions</h1>
<% #sessions.each do |s| %>
<div><%= s.title %></div>
<% end %>
And by the way, you might change your controller to:
class HomeController < ApplicationController
def index
#sessions = Session.all
end
end
For me the problem was the type was not defined in the xml tag
xml.instruct!
xml.posts("type"=>"array") do
#posts.each do |p|
xml.post do
xml.id("type"=>"integer") do
p.id
end
xml.title p.title
xml.content p.content
end
end
end
vs
xml.instruct!
xml.posts do
#posts.each do |p|
xml.post do
xml.id p.id
xml.title p.title
xml.content p.content
end
end
end
Hope this helps you
I had this problem and like Joel above, it was because the type wasn't defined. I found a solution here but briefly if you don't have any control over the XML you can define a custom format, and tell your ActiveResource class to use it:
class TaxAlert < ActiveResource::Base
protected
class CustomFormat
include ActiveResource::Formats::XmlFormat
def decode(xml)
ActiveResource::Formats::XmlFormat.decode(xml)['alert']
end
end
self.format = CustomFormat.new
end

Resources