Error with Rack fetching session-based cookie - ruby

My web app is using Rack 1.4.0, Sinatra v1.2.6, Thin v1.2.11, Ruby v1.9.2p180
Navigating to a page I get this error in the log:
TypeError - can't convert nil into String:
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/cookie.rb:152:in `hexdigest'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/cookie.rb:152:in `generate_hmac'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/cookie.rb:109:in `unpacked_cookie_data'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/cookie.rb:99:in `extract_session_id'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:43:in `load_session_id!'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:32:in `[]'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:262:in `current_session_id'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:268:in `session_exists?'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:107:in `exists?'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:122:in `load_for_read!'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:59:in `[]'
/var/www/phrogz.net/routes/test.rb:8:in `logged_in?'
The code in test.rb line 8 is:
session[ :foo ] == "BAR"
Any suggestions on what to upgrade/downgrade to fix this?

Looks like you run into this issue. The fix is in Rack 1.4.1 so simply upgrading should fix it.

Related

NoMethodError - undefined method `now' for Watir::Time:Class

I get the following error anytime I try to interact with a Watir element.
/Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/wait/timer.rb:40:in `current_time': undefined method `now' for Watir::Time:Class (NoMethodError)
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/wait/timer.rb:6:in `initialize'
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/elements/element.rb:656:in `new'
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/elements/element.rb:656:in `element_call'
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/elements/element.rb:114:in `click'
from fund_cc.rb:8:in `<main>'
Here is my code:
require 'watir'
# require 'time'
b = Watir::Browser.new(:chrome)#, :url => "http://localhost:9515")
b.goto "https://www.bankofamerica.com/"
contact_us= b.link(:text, "Contact Us")
contact_us.click
Does anyone know how to resolve this?
This should be fixed in version 6.0.2.
From Titus Fortner on the Watir-General mailing list:
The latest version of Watir attempts to use monotomic time where
supported and it looks like we grabbed the wrong Time class for where
it is not supported.
I just updated and pushed the fix to 6.0.2. You should be able to just
bundle update now.
I was able to reproduce this behavior. You can monkey patch your gem locally by tweaking the current_time method in /lib/watir/wait/timer.rb:
def current_time
::Time.now.to_f # was Time.now.to_f
end
And I'd suggest logging an issue on https://github.com/watir/watir/issues.

Mcollective Chef service agent failed to run

I have configure mcollective and install following service agent to start/stop service
https://github.com/rottenbytes/mcollective/blob/master/plugins/agents/chef-service.rb
But when i running it, its failing at client.build_node and i am seeing error undefined method reset_defaults_and_overrides for nil:NilClass (NoMethodError)
require 'chef'
require 'chef/client'
require 'chef/run_context'
begin
Chef::Config[:solo] = true
Chef::Config[:log_level] = :debug
Chef::Log.level(:debug)
client = Chef::Client.new
client.run_ohai
client.build_node <-- its failing here
If i try to run on my shell i get following
[root#node1 agent]# ruby /tmp/foo.rb
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/policy_builder/expand_node_object.rb:117:in `build_node': undefined method `reset_defaults_and_overrides' for nil:NilClass (NoMethodError)
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:259:in `build_node'
from /tmp/foo.rb:11:in `<main>'
I am not ruby expert so i don't know how to fix it. I just need clue what is going on
From the looks of it, enough of the internal API for chef client has changed that the mcollective plugin won't work anymore. Try an older version of the chef gem.

Migrating to Rails 3.2 - Undefined method 'session=' for ActionController::Base:Class

I migrated an old Ruby (1.8.7) and Rails (2.2.2) application to Ruby (1.9.3) and Rails (3.2.12) following all of these excellent references:
Rails Upgrade Script
Rails 3 Migration Blog
Booting the Rails 3 App
I am able to start up the app's Rails server but when I access the app via the browser, and then BLAMMO! I get a server error:
!! Unexpected error while processing request: undefined method `session=' for ActionController::Base:Class
When I grep -r for "session =" I get:
/var/www/vendor_sandbox/config/application.rb: config.action_controller.session = {
/var/www/vendor_sandbox/config/environment.rb.rails2: config.action_controller.session = {
/var/www/vendor_sandbox/destroy/config/environment.rb: config.action_controller.session = {
/var/www/vendor_sandbox/generate/config/environment.rb: config.action_controller.session = {
According to a Google search for that error, it's an old issue from Rails 2 so I'm wondering If I missed something in the migration process or if this is something else. Thanks
Here is my terminal session activity:
root#partners:/var/www/vendor_sandbox# ruby -v
ruby 1.9.3p385 (2013-02-06 revision 39114) [i686-linux]
root#partners:/var/www/vendor_sandbox# rails --version
Rails 3.2.12
root#partners:/var/www/vendor_sandbox# rails s
=> Booting Thin
=> Rails 3.2.12 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
Then, I hit the application from a browser and:
!! Unexpected error while processing request: undefined method `session=' for ActionController::Base:Class
Try using config.session_store instead. You'll have to specify the store type, most likely :cookie_store. Here's an example of what it will look like in your application.rb
config.session_store(:cookie_store, {:key => foo, :secret => bar})
Whatever options you had after the session= will go inside that hash there.

Paperclip: NoMethodError (undefined method `match' for nil:NilClass)

I've looked all over the internet trying to find why this error is happening to me.
I'm trying to upload a file using paperclip gem in Rails 3.2.7 and is giving me this error:
NoMethodError in ItemsController#create
undefined method `match' for nil:NilClass
Rails.root: C:/Users/AC_37-PC_BH/RubymineProjects/railstutorial-sample_app_2nd_ed-815d98a
app/controllers/items_controller.rb:20:in `new'
app/controllers/items_controller.rb:20:in `create'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"oYc/V2xKpJVKXPukjrjzQJAboOxI27YXPI42sfDHYaA=",
"item"=>{"item_name"=>"",
"item_pic"=>#<ActionDispatch::Http::UploadedFile:0x3c36678 #original_filename="197623_10150112121221032_1900156_n.jpg",
#content_type="image/jpeg",
#headers="Content-Disposition: form-data; name=\"item[item_pic]\"; filename=\"197623_10150112121221032_1900156_n.jpg\"\r\nContent-Type: image/jpeg\r\n",
#tempfile=#<File:C:/Users/AC_37-~1/AppData/Local/Temp/RackMultipart20120801-6096-q8c9v0>>},
"commit"=>"Create my account"}
I'm including a github to the project so you guys can test it. And try to see what's wrong.
You have to manually access the localhost:3000/items/new to see the page
https://github.com/vinchbr/demo_app
All help would be much appreciated =)
You need to put into Gemfile:
The following code:
gem 'paperclip', '3.0.4'

ruby-openid: #socket not set while performing discovery

I'm having a bit of truble with omniauth/openid.
When trying to authenticate, I found this in my logs:
OpenID::FetchingError: Error fetching https://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username: undefined method `io' for nil:NilClass
The important thing there is undefined method io' for nil:NilClass which comes from openid/fetchers.rb, in the following snippet:
module Net
class HTTP
def post_connection_check(hostname)
check_common_name = true
cert = #socket.io.peer_cert
cert.extensions.each { |ext|
next if ext.oid != "subjectAltName"
ext.value.split(/,\s+/).each{ |general_name|
if /\ADNS:(.*)/ =~ general_name
check_common_name = false
...
That error is generated by #socket.io.peer_cert, #socket is not defined.
Have any of you encountered this before? Not quite sure what the cause is.
Versions I'm running:
ruby 1.9.3dev (2010-08-17 trunk 29020) [x86_64-darwin10.4.0]
ruby-openid (2.1.8)
ruby-openid-apps-discovery (1.2.0)
omniauth 0.2.0
We had this same problem and it was a direct result of Net::HTTP#connect never being invoked. Turns out we had the fakeweb gem scoped into the environment that was throwing the error (development, in our case).
Narrowing fakeweb's scope allows for normal processing of #connect and #socket is once again happy.
group :test do
gem 'fakeweb'
end
We came across the same / very similar problem with both fakeweb and webmock (when using the VCR gem). Switching from fakeweb to typhoeus seemed to have solved this problem for us.

Resources