Ruby giving "NoMethodError: undefined method `[]' for nil:NilClass" with Sinatra - ruby

I am total newbie to Ruby and Sinatra and I am trying to learn them.
So this is my ruby code (File: ruby_test2.rb)
#!/usr/bin/ruby
require 'rubygems'
class LearnRuby
def initalize
#listen = Hash.new { |hash, key| hash[key] = []; }
end
def fill_listen(uid, mid)
#listen[uid]<<=mid
"In fill_listen #{#listen}\n"
end
end
And this is my Sinatra code (file: sinatra_test2.rb)
require 'sinatra'
require './ruby_test2'
if __FILE__ == $0
lr = LearnRuby.new
end
post '/listen' do
lr.fill_listen params[:uid] , params[:mid]
end
An this is how I am running it.
ruby sinatra_test2.rb <-- Starts the server
curl --data "uid=u1&mid=m312" http://localhost:4567/listen <-- Curl command for post request
When I execute the above I get this error (on server and client(curl) side)
localhost - - [22/Mar/2014:22:54:19 IST] "POST /listen HTTP/1.1" 500 3770
- -> /listen
NoMethodError - undefined method `[]' for nil:NilClass:
<path>/ruby_test2.rb:11:in `fill_listen'
sinatra_test2.rb:9:in `block in <main>'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1593:in `call'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1593:in `block in compile!'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:957:in `[]'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:957:in `block (3 levels) in route!'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:976:in `route_eval'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:957:in `block (2 levels) in route!'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:997:in `block in process_route'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:995:in `catch'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:995:in `process_route'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:955:in `block in route!'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:954:in `each'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:954:in `route!'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1067:in `block in dispatch!'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `block in invoke'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `catch'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `invoke'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1064:in `dispatch!'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:889:in `block in call!'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `block in invoke'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `catch'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `invoke'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:889:in `call!'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:877:in `call'
/var/lib/gems/1.9.1/gems/rack-protection-1.5.2/lib/rack/protection/xss_header.rb:18:in `call'
/var/lib/gems/1.9.1/gems/rack-protection-1.5.2/lib/rack/protection/path_traversal.rb:16:in `call'
/var/lib/gems/1.9.1/gems/rack-protection-1.5.2/lib/rack/protection/json_csrf.rb:18:in `call'
/var/lib/gems/1.9.1/gems/rack-protection-1.5.2/lib/rack/protection/base.rb:50:in `call'
/var/lib/gems/1.9.1/gems/rack-protection-1.5.2/lib/rack/protection/base.rb:50:in `call'
/var/lib/gems/1.9.1/gems/rack-protection-1.5.2/lib/rack/protection/frame_options.rb:31:in `call'
/var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/logger.rb:15:in `call'
/var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:217:in `call'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:210:in `call'
/var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
/var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/show_exceptions.rb:21:in `call'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:180:in `call'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:2004:in `call'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1469:in `block in call'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1778:in `synchronize'
/var/lib/gems/1.9.1/gems/sinatra-1.4.4/lib/sinatra/base.rb:1469:in `call'
/var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
localhost - - [22/Mar/2014:22:54:51 IST] "POST /listen HTTP/1.1" 500 3770
I may be missing out on something small but I need help as I am just starting to learn these technologies.
Thanks in advance.

Here is the working example for you, the #listen was nil, because you misspelled initalize -> initialize
require 'sinatra'
class LearnRuby
def initialize
#listen = {}
end
def fill_listen(uid, mid)
#listen[uid] = mid
"In fill_listen #{ #listen }\n"
end
end
post '/listen' do
lr = LearnRuby.new
lr.fill_listen(params[:uid], params[:mid])
end

replace #listen[uid]<<=mid with #listen[uid] = mid
Also, in case you only require initialize to create an empty hash then you can replace #listen = Hash.new { |hash, key| hash[key] = []; } with #listen = {}

Related

Ruby deadlock waiting on Process::Waiter with Open3.popen3

I was using Open3.capture3 in my ruby code and started to notice deadlocks. I did some research and came across this great blog about how open3 can cause deadlocks. Taking this into account I came up with my own capture3 method (still using Open3.popen3) to replace one I was currently using (see below). However I have found that deadlocks still seem to be occurring and the responsible party is the blocking call on the wait_thread.value to get the Process::Status. Looking into Open3 source code I can see this wait_thread is just a Process::Waiter that you get from a Process.detach call. I was wondering what could be causing this deadlock? Is there some way I can check to see if this thread is deadlocked, kill it and return a custom Process::Status (I'd like to return a Process::Status as opposed to just an integer to stay inline with Open3.capture3)
def capture3(cmd)
out_buff = ''
err_buff = ''
chunk_size = 4096
# Progressive timeout array
sleeps = [[0.05]*20,[0.1]*5,[0.5]*3,1,2].flatten
_in, out, err, wait_thread = Open3.popen3(cmd)
_in.close
open_pipes = [out, err]
while !open_pipes.empty?
timeout = sleeps.shift || timeout
ready_pipes, *_ = IO.select(open_pipes, nil, nil, timeout)
ready_pipes.each do |pipe|
tmp = ''
begin
tmp << pipe.readpartial(chunk_size)
rescue EOFError
pipe.close
open_pipes.delete(pipe)
end
out_buff << tmp if pipe == out
err_buff << tmp if pipe == err
end
end
[out_buff, err_buff, wait_thread.value]
end
Note ruby version I'm using is 2.2.5 and running on Mac.
Edit:
The exact error is No live threads left. Deadlock? (fatal) pointing to line number of the wait_thread.value call. I'm calling the capture3 method in another function where I fork the process like so
def fork_process(cmd, options={})
pid = fork {
Process.setproctitle(options[:process_name]) unless options[:process_name].nil?
ENV.merge!(options[:environment])
stdout, stderr, status = capture3(cmd)
yield(stdout, stderr, status) if block_given?
}
Process.detach(pid)
end
Full stacktrace:
/home/myapp/utils.rb:769:in `value': No live threads left. Deadlock? (fatal)
from /home/myapp/utils.rb:769:in `capture3'
from /home/myapp/utils.rb:106:in `block in fork_process'
from /home/myapp/utils.rb:104:in `fork'
from /home/myapp/utils.rb:104:in `fork_process'
from /home/myapp/server.rb:396:in `block in <class:MyServer>'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611:in `block in compile!'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `[]'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `block (3 levels) in route!'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:994:in `route_eval'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `block (2 levels) in route!'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1015:in `block in process_route'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013:in `catch'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013:in `process_route'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:973:in `block in route!'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:972:in `each'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:972:in `route!'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1085:in `block in dispatch!'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `block in invoke'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `catch'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `invoke'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1082:in `dispatch!'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:907:in `block in call!'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `block in invoke'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `catch'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `invoke'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:907:in `call!'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:895:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/rack-1.6.5/lib/rack/nulllogger.rb:9:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/rack-1.6.5/lib/rack/head.rb:13:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/show_exceptions.rb:25:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:182:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:2013:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `block in call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1787:in `synchronize'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/puma-3.8.2/lib/puma/configuration.rb:224:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/puma-3.8.2/lib/puma/server.rb:600:in `handle_request'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/puma-3.8.2/lib/puma/server.rb:435:in `process_client'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/puma-3.8.2/lib/puma/server.rb:299:in `block in run'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/puma-3.8.2/lib/puma/thread_pool.rb:120:in `call'
from /Users/app/.rvm/gems/ruby-2.2.5/gems/puma-3.8.2/lib/puma/thread_pool.rb:120:in `block in spawn_thread'

trying to access aws using ruby API, i get error: http.rb:878:in `initialize': execution expired (Seahorse::Client::NetworkingError)

When trying to access aws via RUBY API with a Simple example, i get error:
ruby getAllInstances.rb
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `initialize': execution expired (Seahorse::Client::NetworkingError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
here is the ruby script:
#!/usr/bin/env ruby
require 'aws-sdk'
ec2 = Aws::EC2::Resource.new(region: 'us-east-1')
# Get all instances with tag key 'Group'
# and tag value 'MyGroovyGroup':
ec2.instances({filters: [{name: 'tag:op_env', values: ['CI']}]}).each do |i|
puts 'ID: ' + i.id
puts 'State: ' + i.state.name
end
here is environment:
$ more credentials
[default]
aws_access_key_id=####ID####
aws_secret_access_key=######key#####
$ more config
[default]
output = json
region = us-east-1
here is another script, which I am trying to use to create a bucket
#!/usr/bin/env ruby
require 'aws-sdk'
#ec2 = Aws::EC2::Resource.new(region: 'us-east-1')
s3 = Aws::S3::Client.new(region: 'us-east-1')
#s3.create_bucket(bucket: 'remove_me')
Aws.use_bundled_cert!
client = Aws::S3::Client.new(
:region => 'us-east-1',
:access_key_id => 'ID',
:secret_access_key => 'KEY'
)
Aws.config[:ssl_verify_peer] = false
resource = Aws::S3::Resource.new(client:client)
bucket = resource.bucket('digital-evidance-perftest-data')
bucket.objects.each do |obj|
resp = client.get_object(response_target:target, bucket:bucketName, key:obj.key)
end
with the same error:
$ruby create_bucket_s3.rb
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `initialize': execution expired (Seahorse::Client::NetworkingError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:877:in `connect'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:857:in `start'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/net_http/connection_pool.rb:285:in `start_session'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/net_http/connection_pool.rb:92:in `session_for'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/net_http/handler.rb:119:in `session'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/net_http/handler.rb:71:in `transmit'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/net_http/handler.rb:45:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/plugins/content_length.rb:12:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_request_signer.rb:88:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_request_signer.rb:23:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/xml/error_handler.rb:8:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/helpful_socket_errors.rb:10:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_request_signer.rb:65:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_redirects.rb:15:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/retry_errors.rb:88:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/retry_errors.rb:119:in `retry_request'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/retry_errors.rb:102:in `retry_if_possible'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/retry_errors.rb:90:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/retry_errors.rb:119:in `retry_request'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/retry_errors.rb:102:in `retry_if_possible'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/retry_errors.rb:90:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/retry_errors.rb:119:in `retry_request'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/retry_errors.rb:102:in `retry_if_possible'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/retry_errors.rb:90:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_dualstack.rb:32:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_accelerate.rb:49:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_md5s.rb:31:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_expect_100_continue.rb:21:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_bucket_name_restrictions.rb:12:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_bucket_dns.rb:31:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/rest/handler.rb:7:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/user_agent.rb:12:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/plugins/endpoint.rb:41:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_url_encoded_keys.rb:40:in `manage_keys'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_url_encoded_keys.rb:32:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/param_validator.rb:21:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/plugins/raise_response_errors.rb:14:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_sse_cpk.rb:19:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_dualstack.rb:24:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/s3_accelerate.rb:34:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:20:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/idempotency_token.rb:18:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/param_converter.rb:20:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/aws-sdk-core/plugins/response_paging.rb:26:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/plugins/response_target.rb:21:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/request.rb:70:in `send_request'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.9.11/lib/seahorse/client/base.rb:207:in `block (2 levels) in define_operation_methods'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-resources-2.9.11/lib/aws-sdk-resources/request.rb:24:in `call'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-resources-2.9.11/lib/aws-sdk-resources/operations.rb:139:in `all_batches'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-resources-2.9.11/lib/aws-sdk-resources/collection.rb:18:in `each'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-resources-2.9.11/lib/aws-sdk-resources/collection.rb:18:in `each'
from create_bucket_s3.rb:19:in `<main>'
This error was due to http proxy not exported in the environment
Once i added proxies i was able to communicate with aws via ruby sdk

Delayed Job Delayed::PerformableMethod undefined method "delayed_task" for #<Class:0x0000000b4dcd20>

I am using delayed jobs and I think I have a problem with serialization. We are using ruby 2.2.2.
In my model I have a callback that fires on save and creates a delayed job for my model. like this:
after_create :update_queue
def update_queue
self.class.delay(run_at: 1.minutes.from_now, delayed_reference_id: self.id, delayed_reference_type: "Payment", queue: "qbo_payments").delayed_task(self.id)
end
def self.delayed_task
# Do some stuff
end
However I am getting the error:
undefined method `delayed_task' for #<Class:0x0000000f93f9b8>
~/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
~/shared/bundle/ruby/2.2.0/gems/attr_encrypted-3.0.3/lib/attr_encrypted.rb:295:in `method_missing'
~/shared/bundle/ruby/2.2.0/gems/attr_encrypted-3.0.3/lib/attr_encrypted/adapters/active_record.rb:129:in `method_missing_with_attr_encrypted'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/performable_method.rb:26:in `perform'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/backend/base.rb:84:in `block in invoke_job'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:61:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:61:in `block in initialize'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:66:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:66:in `execute'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:40:in `run_callbacks'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/backend/base.rb:81:in `invoke_job'
~/shared/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb:127:in `block in invoke_job'
~/shared/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:363:in `perform_action_with_newrelic_trace'
~/shared/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb:126:in `invoke_job'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:230:in `block (2 levels) in run'
/usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:89:in `block in timeout'
/usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:99:in `call'
/usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:99:in `timeout'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:230:in `block in run'
/usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:229:in `run'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:306:in `block in reserve_and_run_one_job'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:61:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:61:in `block in initialize'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:66:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:66:in `execute'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:40:in `run_callbacks'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:306:in `reserve_and_run_one_job'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:213:in `block in work_off'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:212:in `times'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:212:in `work_off'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:175:in `block (4 levels) in start'
/usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:174:in `block (3 levels) in start'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:61:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:61:in `block in initialize'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:66:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:66:in `execute'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:40:in `run_callbacks'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:173:in `block (2 levels) in start'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:172:in `loop'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:172:in `block in start'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/plugins/clear_locks.rb:7:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:79:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:79:in `block (2 levels) in add'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:61:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:61:in `block in initialize'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:79:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:79:in `block in add'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:66:in `call'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:66:in `execute'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/lifecycle.rb:40:in `run_callbacks'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/worker.rb:171:in `start'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/command.rb:132:in `run'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/command.rb:120:in `block in run_process'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons/application.rb:265:in `call'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons/application.rb:265:in `block in start_proc'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons/daemonize.rb:84:in `call'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons/daemonize.rb:84:in `call_as_daemon'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons/application.rb:269:in `start_proc'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons/application.rb:295:in `start'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons/controller.rb:69:in `run'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons.rb:193:in `block in run_proc'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons/cmdline.rb:88:in `call'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons/cmdline.rb:88:in `catch_exceptions'
~/shared/bundle/ruby/2.2.0/gems/daemons-1.2.3/lib/daemons.rb:192:in `run_proc'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/command.rb:118:in `run_process'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/command.rb:99:in `block in daemonize'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/command.rb:97:in `times'
~/shared/bundle/ruby/2.2.0/gems/delayed_job-4.1.2/lib/delayed/command.rb:97:in `daemonize'
script/delayed_job:5:in `<main>'"
What I have tried
After a bit of google research I found 2 fixes. The first and more widely accepted fix is to add:
require 'yaml'
YAML::ENGINE.yamler = 'syck'
#https://github.com/collectiveidea/delayed_job/issues/199
However, syck is no longer supported for ruby 2.2.2
The second solution, which only seemed to exacerbate the problem, was to add "bundle exec" to my delayed_job startup script like this:
run "cd #{current_path}; bundle exec script/delayed_job start #{rails_env}"
This will work !
after_create :update_queue
def update_queue
self.delay(run_at: 1.minutes.from_now, delayed_reference_id: self.id, delayed_reference_type: "Payment", queue: "qbo_payments").delayed_task()
end
def delayed_task
self.class.delayed_task(self.id)
end
def self.delayed_task
# Do some stuff
end

Can't successfully find a Twilio subaccount with twilio-rb

Big fan of using twilio-rb over twilio-ruby, but i'm stuck when trying to provide the Twilio subaccount's friendly_name to request the account_sid.
app.rb
Twilio::Config.setup \
:account_sid => '[MAIN ACCOUNT_SID]',
:auth_token => '[AUTH_TOKEN]'
subaccount.rb
post '/subaccount/create' do
Twilio::Account.create :friendly_name => params[:friendly_name]
account = Twilio::Account.find :friendly_name => params[:friendly_name]
#subaccount = Subaccount.new
#subaccount.friendly_name = params[:friendly_name]
#subaccount.account_sid = account.sid
if #subaccount.save
redirect '/subaccount/create'
else
erb 'There has been an error saving.'
end
end
It creates the subaccount in Twilio just fine, it does not however find the subaccount with the friendly_name.
When I break this down further, I have a subaccount named 'hello' and I want the SID for it:
account = Twilio::Account.find :friendly_name => "hello"
puts account.sid
This is what is returned in the Terminal
Called from: /Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/builder.rb:86:in `new'.
URI::InvalidURIError - bad URI(is not URI?): /Accounts/{:friendly_name=>"hello"}.json:
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri/common.rb:176:in `split'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri/common.rb:211:in `parse'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri/common.rb:747:in `parse'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/httparty-0.10.2/lib/httparty/request.rb:44:in `path='
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/httparty-0.10.2/lib/httparty/request.rb:33:in `initialize'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/httparty-0.10.2/lib/httparty.rb:456:in `new'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/httparty-0.10.2/lib/httparty.rb:456:in `perform_request'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/httparty-0.10.2/lib/httparty.rb:398:in `get'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/twilio-rb-2.3.0/lib/twilio/resource.rb:116:in `block (2 levels) in singleton class'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/twilio-rb-2.3.0/lib/twilio/finder.rb:9:in `find'
/Users/chadsakonchick/Projects/cloud-phone/lib/subaccounts.rb:27:in `block in <top (required)>'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/session/abstract/id.rb:225:in `context'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/session/abstract/id.rb:220:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/logger.rb:15:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/commonlogger.rb:33:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:217:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:210:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/head.rb:13:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/methodoverride.rb:22:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:89:in `service'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
[2014-11-07 18:22:32] ERROR NoMethodError: undefined method `join' for #<String:0x007fc7548fa570>
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:37:in `rescue in call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:89:in `service'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
localhost - - [07/Nov/2014:18:22:32 CST] "GET /subaccount/twilio-rb/hello HTTP/1.1" 500 340
Try this:
account = Twilio::Account.all :friendly_name => "hello"
puts account[0].sid
It took me a few minutes of digging in the twilio-rb gem, it's the Finder class that is being included into the Account class that does the work. In this scenario we want to use the API List resource which Stevie and co supported with the all method with a filter parameter.
Using the find method requires the account SID, and doesn't seem to support parameters. I think it might be worth making a pull request to add this to the documentation, as it's not obvious.
Update
See above as I added the [0] indexer to account as this is an Array.

Ruby IO Error, not opened for reading

Using OmniAuth for Facebook with Sinatra and Ruby 1.9.3. Getting the IO not opened for reading error during the latter stage of the auth process. Haven't seen much else about this online. If you require any more info please let me know.
Failing on the MultiJson line:
get '/auth/failure' do
content_type 'application/json'
MultiJson.encode(request.env)
end
Error:
IOError at /auth/facebook/callback
not opened for reading
file: encoding.rb location: each line: 256
Detailed error log:
== Sinatra/1.4.4 has taken the stage on 4567 for development with backup from Thin
Thin web server (v1.6.1 codename Death Proof)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop
SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
This poses a security threat. It is strongly recommended that you
provide a secret to prevent exploits that may be possible from crafted
cookies. This will not be supported in future versions of Rack, and
future versions will even invalidate your existing user cookies.
Called from: /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/builder.rb:86:in `new'.
127.0.0.1 - - [08/Dec/2013 18:34:03] "GET / HTTP/1.1" 302 - 0.0025
I, [2013-12-08T18:34:03.828713 #927] INFO -- omniauth: (facebook) Request phase initiated.
127.0.0.1 - - [08/Dec/2013 18:34:03] "GET /auth/facebook HTTP/1.1" 302 203 0.0049
I, [2013-12-08T18:34:04.278981 #927] INFO -- omniauth: (facebook) Callback phase initiated.
IOError - not opened for reading:
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:256:in `each'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:256:in `to_a'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:256:in `as_json'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:58:in `block in as_json'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:81:in `check_for_circular_references'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:57:in `as_json'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:296:in `block in as_json'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:296:in `each'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:296:in `map'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:296:in `as_json'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:50:in `block in encode'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:81:in `check_for_circular_references'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:49:in `encode'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:34:in `encode'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/core_ext/object/to_json.rb:16:in `to_json'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/multi_json-1.8.2/lib/multi_json/adapters/json_common.rb:21:in `dump'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/multi_json-1.8.2/lib/multi_json/adapter.rb:24:in `dump'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/multi_json-1.8.2/lib/multi_json.rb:137:in `dump'
app.rb:87:in `block in <main>'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1593:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1593:in `block in compile!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:957:in `[]'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:957:in `block (3 levels) in route!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:976:in `route_eval'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:957:in `block (2 levels) in route!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:997:in `block in process_route'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:995:in `catch'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:995:in `process_route'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:955:in `block in route!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:954:in `each'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:954:in `route!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1067:in `block in dispatch!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `block in invoke'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `catch'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `invoke'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1064:in `dispatch!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:889:in `block in call!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `block in invoke'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `catch'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `invoke'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:889:in `call!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:877:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:401:in `call_app!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:363:in `callback_phase'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-oauth2-1.0.3/lib/omniauth/strategies/oauth2.rb:65:in `callback_phase'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:226:in `callback_call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:182:in `call!'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:164:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/builder.rb:49:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-protection-1.5.1/lib/rack/protection/xss_header.rb:18:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-protection-1.5.1/lib/rack/protection/path_traversal.rb:16:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-protection-1.5.1/lib/rack/protection/json_csrf.rb:18:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-protection-1.5.1/lib/rack/protection/base.rb:50:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-protection-1.5.1/lib/rack/protection/base.rb:50:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/logger.rb:15:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:217:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:210:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/show_exceptions.rb:21:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:180:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:2004:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1469:in `block in call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1778:in `synchronize'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1469:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/thin-1.6.1/lib/thin/connection.rb:82:in `block in pre_process'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/thin-1.6.1/lib/thin/connection.rb:80:in `catch'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/thin-1.6.1/lib/thin/connection.rb:80:in `pre_process'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/eventmachine-1.0.3/lib/eventmachine.rb:1037:in `call'
/Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/eventmachine-1.0.3/lib/eventmachine.rb:1037:in `block in spawn_threadpool'
Turns out a GEM conflict was the issue. I fixed the problem with the code from an indirectly related question that used Rails instead. Please see below:
#fix for JSON gem/activesupport bug. More info: http://stackoverflow.com/questions/683989/how-do-you-deal-with-the-conflict-between-activesupportjson-and-the-json-gem
if defined?(ActiveSupport::JSON)
[Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].each do |klass|
klass.class_eval do
def to_json(*args)
super(args)
end
def as_json(*args)
super(args)
end
end
end
end

Resources