Thin raises missing template exceptions rarely - ruby-on-rails

On my prod server I'm getting Missing template exceptions sometime.
The setup is VPN with CentOS5, ruby 1.9.2, Rails 3.2.1, 8 nginx instances, 6 thin instances
So, this happens with two main views, happens rarely, approx. 1 time per 1000 requests, but it is
As I understand thin recieves the request and just process with real exception, but I cannot realize why, because 999 of 1000 other request are ok and they must be ok.
Is this a filesystem issue? or smth with locale from bots?
exception example is here:
From: Exception Notifier <myhost>
Subject: [myhost Exception] controllername#actionname (ActionView::MissingTemplate) "Missing
template controllername/actionname, application/actionname with {:locale=>[...
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Gm-Message-State: ALoCoQn4St5gK1z...
A ActionView::MissingTemplate occurred in controllername#actionname:
Missing template controllername/actionname, application/actionname with {:locale=3D>[:en], :fo=
rmats=3D>[:html], :handlers=3D>[:erb, :builder, :coffee, :haml]}. Searche=
d in:
* "/..mypath../releases/20120205001108/app/views"
actionpack (3.2.1) lib/action_view/path_set.rb:58:in `find'
-------------------------------
Request:
-------------------------------
* URL : http://myhost/actionurl
* IP address: 74.208.8.48
* Parameters: {"utf8"=3D>"=E2=9C=93", "authenticity_token"=3D>"Ffkm6Bd8=
wi3+Got7uTeLhzj86hJNDpFYRjG4Yrqx4yQ=3D", "video_link"=3D>"", "controller"=
=3D>"controllername", "action"=3D>"actionname"}
* Rails root: /..mypath../releases/20120205001108
-------------------------------
Session:
-------------------------------
* session id: "0c7c55faac70eb0632139de299ccdc9a"
* data: {"session_id"=3D>"0c7c55faac70eb0632139de299ccdc9a",
"_csrf_token"=3D>"Ffkm6Bd8wi3+Got7uTeLhzj86hJNDpFYRjG4Yrqx4yQ=3D"}
-------------------------------
Environment:
-------------------------------
* CONTENT_LENGTH : 94
* CONTENT_TYPE : application/x-www-fo=
rm-urlencoded
* GATEWAY_INTERFACE : CGI/1.2
* HTTP_ACCEPT : image/gif, image/x-x=
bitmap, image/jpeg, image/pjpeg, */*
* HTTP_ACCEPT_ENCODING : gzip, deflate
* HTTP_ACCEPT_LANGUAGE : en-us
* HTTP_CONNECTION : close
* HTTP_COOKIE : _myhost_session=3DBA=
h7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTBjN2M1NWZhYWM3MGViMDYzMjEzOWRlMjk5Y2NkYzl=
hBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMUZma202QmQ4d2kzK0dvdDd1VGVMaHpqODZoSk5E=
cEZZUmpHNFlycXg0eVE9BjsARg%3D%3D--7766b6f664ae053b5682f046ad3531e5a41bcdf=
d
* HTTP_HOST : myhost
* HTTP_MAX_FORWARDS : 10
* HTTP_PRAGMA : no-cache
* HTTP_REFERER : http://myhost/
* HTTP_USER_AGENT : Mozilla/4.0 (compati=
ble; MSIE 6.0; Windows NT 5.1)
* HTTP_VERSION : HTTP/1.0
* HTTP_X_FORWARDED_FOR : 74.208.8.48
* HTTP_X_REAL_IP : 74.208.8.48
* ORIGINAL_FULLPATH : /actionurl
* PATH_INFO : /actionurl
* QUERY_STRING : =
* REMOTE_ADDR : 127.0.0.1
* REQUEST_METHOD : POST
* REQUEST_PATH : /actionurl
* REQUEST_URI : /actionurl
* SCRIPT_NAME : =
* SERVER_NAME : myhost
* SERVER_PORT : 80
* SERVER_PROTOCOL : HTTP/1.1
* SERVER_SOFTWARE : thin 1.3.1 codename =
Triple Espresso
* action_controller.instance : controllername#actionname
* action_dispatch.backtrace_cleaner : #<Rails::BacktraceCl=
eaner:0xab76b14>
* action_dispatch.cookies : #<ActionDispatch::Co=
okies::CookieJar:0xcaedac4>
* action_dispatch.logger : #<ActiveSupport::Tag=
gedLogging:0xadb7874>
* action_dispatch.parameter_filter : [:password, /RAW_POS=
T_DATA/, /RAW_POST_DATA/, /RAW_POST_DATA/, /RAW_POST_DATA/, /RAW_POST_DAT=
A/, /RAW_POST_DATA/, /RAW_POST_DATA/, /RAW_POST_DATA/, /RAW_POST_DATA/, /=
RAW_POST_DATA/, /RAW_POST_DATA/, /RAW_POST_DATA/, /RAW_POST_DATA/, /RAW_P=
OST_DATA/, /RAW_POST_DATA/, /RAW_POST_DATA/, /RAW_POST_DATA/]
* action_dispatch.remote_ip : 74.208.8.48
* action_dispatch.request.content_type : application/x-www-fo=
rm-urlencoded
* action_dispatch.request.formats : [text/html]
* action_dispatch.request.parameters : {"utf8"=3D>"=E2=9C=93=
", "authenticity_token"=3D>"Ffkm6Bd8wi3+Got7uTeLhzj86hJNDpFYRjG4Yrqx4yQ=3D=
", "someparam"=3D>"", "controller"=3D>"controllername", "action"=3D>"actionname"}
* action_dispatch.request.path_parameters : {:controller=3D>"controllername", :action=3D>"actionname"}
* action_dispatch.request.query_parameters : {}
* action_dispatch.request.request_parameters : {"utf8"=3D>"=E2=9C=93=
", "authenticity_token"=3D>"Ffkm6Bd8wi3+Got7uTeLhzj86hJNDpFYRjG4Yrqx4yQ=3D=
", "video_link"=3D>""}
* action_dispatch.request.unsigned_session_cookie: {"session_id"=3D>"0c=
7c55faac70eb0632139de299ccdc9a", "_csrf_token"=3D>"Ffkm6Bd8wi3+Got7uTeLhz=
j86hJNDpFYRjG4Yrqx4yQ=3D"}
* action_dispatch.request_id : 3e96f7bca9fc30f3e4eb=
1d91e61a63c0
* action_dispatch.routes : #<ActionDispatch::Ro=
uting::RouteSet:0xb0b029c>
* action_dispatch.secret_token : 20b9fbcf1214f8f88d5e=
549c61892c2558dffbe59db6c9dda63c84554af6d628248f3fd5217eb12e47df41260789a=
e59ad359b67e2309e5832390244777d56a7
* action_dispatch.show_detailed_exceptions : false
* action_dispatch.show_exceptions : true
* async.callback : #<Method: Thin::Unix=
Connection(Thin::Connection)#post_process>
* async.close : #<EventMachine::Defa=
ultDeferrable:0xcacf7a4>
* exception_notifier.options : {:sender_address=3D>=
"\"myhost Exception Notifier\" <exception#email>", :exception_recipients=3D>=
["exception#email"], :email_prefix=3D>"[myhost Exception] ", :sections=3D>["=
request", "session", "environment", "backtrace"], :ignore_exceptions=3D>[=
ActiveRecord::RecordNotFound, AbstractController::ActionNotFound, ActionC=
ontroller::RoutingError]}
* rack-cache.allow_reload : false
* rack-cache.allow_revalidate : false
* rack-cache.cache_key : Rack::Cache::Key
* rack-cache.default_ttl : 0
* rack-cache.entitystore : rails:/
* rack-cache.metastore : rails:/
* rack-cache.private_headers : ["Authorization", "C=
ookie"]
* rack-cache.storage : #<Rack::Cache::Stora=
ge:0xc2b79b8>
* rack-cache.use_native_ttl : false
* rack-cache.verbose : true
* rack.errors : #<IO:0x99b5b50>
* rack.input : #<StringIO:0xcaa0bac=
>
* rack.multiprocess : false
* rack.multithread : false
* rack.request.cookie_hash : {"_myhost_session"=3D=
>"BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTBjN2M1NWZhYWM3MGViMDYzMjEzOWRlMjk5Y2N=
kYzlhBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMUZma202QmQ4d2kzK0dvdDd1VGVMaHpqODZo=
Sk5EcEZZUmpHNFlycXg0eVE9BjsARg=3D=3D--7766b6f664ae053b5682f046ad3531e5a41=
bcdfd"}
* rack.request.cookie_string : _myhost_session=3DBA=
h7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTBjN2M1NWZhYWM3MGViMDYzMjEzOWRlMjk5Y2NkYzl=
hBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMUZma202QmQ4d2kzK0dvdDd1VGVMaHpqODZoSk5E=
cEZZUmpHNFlycXg0eVE9BjsARg%3D%3D--7766b6f664ae053b5682f046ad3531e5a41bcdf=
d
* rack.request.form_hash : {"utf8"=3D>"=E2=9C=93=
", "authenticity_token"=3D>"Ffkm6Bd8wi3+Got7uTeLhzj86hJNDpFYRjG4Yrqx4yQ=3D=
", "someparam"=3D>""}
* rack.request.form_input : #<StringIO:0xcaa0bac=
>
* rack.request.form_vars : utf8=3D%E2%9C%93&aut=
henticity_token=3DFfkm6Bd8wi3%2BGot7uTeLhzj86hJNDpFYRjG4Yrqx4yQ%3D&video_=
link=3D
* rack.request.query_hash : {}
* rack.request.query_string : =
* rack.run_once : false
* rack.session : {"session_id"=3D>"0c=
7c55faac70eb0632139de299ccdc9a", "_csrf_token"=3D>"Ffkm6Bd8wi3+Got7uTeLhz=
j86hJNDpFYRjG4Yrqx4yQ=3D"}
* rack.session.options : {:path=3D>"/", :doma=
in=3D>nil, :expire_after=3D>nil, :secure=3D>false, :httponly=3D>true, :de=
fer=3D>false, :renew=3D>false, :coder=3D>#<Rack::Session::Cookie::Base64:=
:Marshal:0xc26f410>, :id=3D>"0c7c55faac70eb0632139de299ccdc9a"}
* rack.url_scheme : http
* rack.version : [1, 0]
=
* Process: 13504
* Server : myserver
-------------------------------
Backtrace:
-------------------------------
actionpack (3.2.1) lib/action_view/path_set.rb:58:in `find'
actionpack (3.2.1) lib/action_view/lookup_context.rb:109:in `find'
actionpack (3.2.1) lib/action_view/renderer/abstract_renderer.rb:3:in `=
find_template'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:28:in =
`determine_template'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:10:in =
`render'
actionpack (3.2.1) lib/action_view/renderer/renderer.rb:36:in `render_t=
emplate'
actionpack (3.2.1) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:109:in `_render=
_template'
actionpack (3.2.1) lib/action_controller/metal/streaming.rb:225:in `_re=
nder_template'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:103:in `render_=
to_body'
actionpack (3.2.1) lib/action_controller/metal/renderers.rb:28:in `rend=
er_to_body'
actionpack (3.2.1) lib/action_controller/metal/compatibility.rb:50:in `=
render_to_body'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:16:in `rend=
er'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:40:in=
`block (2 levels) in render'
activesupport (3.2.1) lib/active_support/core_ext/benchmark.rb:5:in `bl=
ock in ms'
/usr/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
activesupport (3.2.1) lib/active_support/core_ext/benchmark.rb:5:in `ms=
'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:40:in=
`block in render'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:83:in=
`cleanup_view_runtime'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:2=
4:in `cleanup_view_runtime'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:39:in=
`render'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:10:in=
`default_render'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:5:in =
`send_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:167:in `process_acti=
on'
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:10:in `proc=
ess_action'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:18:in `block in=
process_action'
activesupport (3.2.1) lib/active_support/callbacks.rb:414:in `_run__858=
933213__process_action__417312363__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_cal=
lback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_proc=
ess_action_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callba=
cks'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:17:in `process_=
action'
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:in `process=
_action'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in=
`block in process_action'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block=
in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:=
20:in `instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instr=
ument'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in=
`process_action'
actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:in=
`process_action'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:1=
8:in `process_action'
newrelic_rpm (3.3.1) lib/new_relic/agent/instrumentation/rails3/action_=
controller.rb:34:in `block in process_action'
newrelic_rpm (3.3.1) lib/new_relic/agent/instrumentation/controller_ins=
trumentation.rb:255:in `block in perform_action_with_newrelic_trace'
newrelic_rpm (3.3.1) lib/new_relic/agent/method_tracer.rb:242:in `trace=
_execution_scoped'
newrelic_rpm (3.3.1) lib/new_relic/agent/instrumentation/controller_ins=
trumentation.rb:250:in `perform_action_with_newrelic_trace'
newrelic_rpm (3.3.1) lib/new_relic/agent/instrumentation/rails3/action_=
controller.rb:33:in `process_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process'=
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in=
`dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in acti=
on'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call=
'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `disp=
atch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call=
'
journey (1.0.1) lib/journey/router.rb:68:in `block in call'
journey (1.0.1) lib/journey/router.rb:56:in `each'
journey (1.0.1) lib/journey/router.rb:56:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in `cal=
l'
newrelic_rpm (3.3.1) lib/new_relic/rack/browser_monitoring.rb:23:in `ca=
ll'
exception_notification (2.5.2) lib/exception_notifier.rb:25:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_suppor=
t.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:i=
n `call'
actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call=
'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `ca=
ll'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/con=
nection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `b=
lock in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__332=
759817__call__1023748432__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_cal=
lback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call=
_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callba=
cks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `c=
all'
rack (1.4.1) lib/rack/sendfile.rb:102:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `c=
all'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:1=
6:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56=
:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `=
call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:=
72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
rack-cache (1.1) lib/rack/cache/context.rb:132:in `forward'
rack-cache (1.1) lib/rack/cache/context.rb:139:in `pass'
rack-cache (1.1) lib/rack/cache/context.rb:151:in `invalidate'
rack-cache (1.1) lib/rack/cache/context.rb:70:in `call!'
rack-cache (1.1) lib/rack/cache/context.rb:50:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
railties (3.2.1) lib/rails/railtie/configurable.rb:30:in `method_missin=
g'
thin (1.3.1) lib/thin/connection.rb:80:in `block in pre_process'
thin (1.3.1) lib/thin/connection.rb:78:in `catch'
thin (1.3.1) lib/thin/connection.rb:78:in `pre_process'
thin (1.3.1) lib/thin/connection.rb:53:in `process'
thin (1.3.1) lib/thin/connection.rb:38:in `receive_data'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run_machine'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run'
thin (1.3.1) lib/thin/backends/base.rb:61:in `start'
thin (1.3.1) lib/thin/server.rb:159:in `start'
thin (1.3.1) lib/thin/controllers/controller.rb:86:in `start'
thin (1.3.1) lib/thin/runner.rb:185:in `run_command'
thin (1.3.1) lib/thin/runner.rb:151:in `run!'
thin (1.3.1) bin/thin:6:in `<top (required)>'
/..mypath../shared/bundle/ruby/1.9.1/bin/thin:19:in `load'
/..mypath../shared/bundle/ruby/1.9.1/bin/thin:19:in `<main>'

Is this supposed to be a POST request? That's what's showing up in the stacktrace:
REQUEST_METHOD : POST

Related

How to solve this following issue, SocketError "Failed to open TCP connection to server_name:xxxx (getaddrinfo: Temporary failure in name resolution)?

I got this issue when I tried to access any endpoints from the main domain (running in UBUNTU 18.04 LTS app_server).
But, this issue is not always happened, sometimes it works fine.
And there is no issue, if I access any endpoints from the staging environment (using UBUNTU 16.04.7 LTS).
I'm using the KONG as the API Gateway (running as container in CentOS 7.9.2009 kong_server).
KONG 2.0.1
LuaJIT 2.1.0-beta3
All servers are using the same private network and the same private DNS server.
We've tried bypass our NGINX Proxy Server when the main domain accessing any endpoints (by using kong_server:xxxx).
Please advice me, if I need to provide more information to solve this issue.
Looking forward for the solution or any hints for this issue.
Thanks.
This is the log of the error.
A SocketError occurred in home#index:
Failed to open TCP connection to kong_server:xxxx (getaddrinfo: Temporary failure in name resolution)
app/models/app.rb:4:in `search'
-------------------------------
Request:
-------------------------------
* URL : http://main_domain.com/
* HTTP Method: GET
* IP address : x.x.x.x
* Parameters : {"controller"=>"home", "action"=>"index"}
* Timestamp : 2022-11-25 09:03:56 UTC
* Server : app_server
* Rails root : /app_directory_path/releases/20221124230456
* Process: 56037
-------------------------------
Session:
-------------------------------
ERROR: Failed to generate exception summary:
ActionView::Template::Error: undefined method `public_id' for "17a418e4db5e22d84ee5082d66525685":String
Did you mean? public_send
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/request/session.rb:96:in `[]'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier/views/exception_notifier/_session.text.erb:1:in `__app_directory_path_shared_bundle_ruby_______gems_exception_notification_______lib_exception_notifier_views_exception_notifier__session_text_erb___1259887619874614720_70094959924340'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/template.rb:159:in `block in render'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:170:in `instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/template.rb:354:in `instrument_render_template'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/template.rb:157:in `render'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/partial_renderer.rb:344:in `block in render_partial'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:168:in `block in instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:168:in `instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/partial_renderer.rb:333:in `render_partial'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/partial_renderer.rb:312:in `render'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/renderer.rb:49:in `render_partial'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/helpers/rendering_helper.rb:36:in `render'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb:9:in `block in __app_directory_path_shared_bundle_ruby_______gems_exception_notification_______lib_exception_notifier_views_exception_notifier_exception_notification_text_erb__3365026513843035604_70094968707260'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb:7:in `map'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb:7:in `__app_directory_path_shared_bundle_ruby_______gems_exception_notification_______lib_exception_notifier_views_exception_notifier_exception_notification_text_erb__3365026513843035604_70094968707260'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/template.rb:159:in `block in render'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:170:in `instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/template.rb:354:in `instrument_render_template'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/template.rb:157:in `render'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:168:in `block in instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:168:in `instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/template_renderer.rb:52:in `render_template'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/template_renderer.rb:16:in `render'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/renderer.rb:44:in `render_template'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/renderer/renderer.rb:25:in `render'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/rendering.rb:103:in `_render_template'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/rendering.rb:84:in `render_to_body'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/abstract_controller/rendering.rb:25:in `render'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/base.rb:919:in `block in collect_responses'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/collector.rb:28:in `custom'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/abstract_controller/collector.rb:11:in `text'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier/email_notifier.rb:136:in `block in compose_email'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/base.rb:920:in `collect_responses'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/base.rb:828:in `mail'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier/email_notifier.rb:135:in `compose_email'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier/email_notifier.rb:57:in `exception_notification'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/abstract_controller/base.rb:194:in `process_action'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:98:in `run_callbacks'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/abstract_controller/callbacks.rb:41:in `process_action'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/abstract_controller/base.rb:134:in `process'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/rescuable.rb:25:in `block in process'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/rescuable.rb:17:in `handle_exceptions'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/rescuable.rb:24:in `process'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionview-5.2.4.1/lib/action_view/rendering.rb:32:in `process'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/base.rb:607:in `block in process'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:168:in `block in instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:168:in `instrument'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/base.rb:606:in `process'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/message_delivery.rb:123:in `block in processed_mailer'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/message_delivery.rb:122:in `tap'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/message_delivery.rb:122:in `processed_mailer'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionmailer-5.2.4.1/lib/action_mailer/message_delivery.rb:29:in `__getobj__'
/home/baf/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/delegate.rb:80:in `method_missing'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier/email_notifier.rb:171:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier.rb:162:in `fire_notification'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier.rb:71:in `block in notify_exception'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier.rb:69:in `each'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notifier.rb:69:in `notify_exception'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notification/rack.rb:59:in `rescue in call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/exception_notification-4.4.3/lib/exception_notification/rack.rb:48:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/rack-2.1.2/lib/rack/tempfile_reaper.rb:17:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/rack-2.1.2/lib/rack/etag.rb:27:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/rack-2.1.2/lib/rack/conditional_get.rb:27:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/rack-2.1.2/lib/rack/head.rb:14:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/rack-2.1.2/lib/rack/session/abstract/id.rb:269:in `context'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/rack-2.1.2/lib/rack/session/abstract/id.rb:263:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/cookies.rb:670:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:98:in `run_callbacks'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.1/lib/rails/rack/logger.rb:38:in `call_app'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.1/lib/rails/rack/logger.rb:26:in `block in call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/tagged_logging.rb:71:in `block in tagged'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/tagged_logging.rb:28:in `tagged'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/tagged_logging.rb:71:in `tagged'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.1/lib/rails/rack/logger.rb:26:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/request_id.rb:27:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/rack-2.1.2/lib/rack/method_override.rb:24:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/rack-2.1.2/lib/rack/runtime.rb:24:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/static.rb:127:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/rack-2.1.2/lib/rack/sendfile.rb:113:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.1/lib/rails/engine.rb:524:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/configuration.rb:228:in `call'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/server.rb:681:in `handle_request'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/server.rb:472:in `process_client'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/server.rb:328:in `block in run'
/app_directory_path/shared/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/thread_pool.rb:134:in `block in spawn_thread'
-------------------------------
Environment:
-------------------------------
* GATEWAY_INTERFACE : CGI/1.2
* HTTP_ACCEPT : text/html, application/xhtml+xml
* HTTP_ACCEPT_ENCODING : gzip, deflate, br
* HTTP_ACCEPT_LANGUAGE : en-US,en;q=0.9
* HTTP_CONNECTION : keep-alive
* HTTP_COOKIE : _ga=GA1.3.851066951.1664247544; _fbp=fb.2.1664247548458.1010494553; _rack-cas-app_session=17a418e4db5e22d84ee5082d66525685
* HTTP_HOST : main_domain.com
* HTTP_IF_NONE_MATCH : W/"64a9d2514994c88c912210a97520c186"
* HTTP_ORIGIN : http://main_domain.com
* HTTP_REFERER : https://main_domain.com/approvals
* HTTP_SEC_CH_UA : "Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"
* HTTP_SEC_CH_UA_MOBILE : ?0
* HTTP_SEC_CH_UA_PLATFORM : "Windows"
* HTTP_SEC_FETCH_DEST : empty
* HTTP_SEC_FETCH_MODE : cors
* HTTP_SEC_FETCH_SITE : same-origin
* HTTP_TURBOLINKS_REFERRER : https://main_domain.com/approvals
* HTTP_USER_AGENT : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
* HTTP_VERSION : HTTP/1.1
* HTTP_X_FORWARDED_FOR : 10.0.y.y
* ORIGINAL_FULLPATH : /
* ORIGINAL_SCRIPT_NAME :
* PATH_INFO : /
* QUERY_STRING :
* REMOTE_ADDR : x.x.x.x
* REQUEST_METHOD : GET
* REQUEST_PATH : /
* REQUEST_URI : /
* ROUTES_47152330688340_SCRIPT_NAME :
* SCRIPT_NAME :
* SERVER_NAME : main_domain.com
* SERVER_PORT : 80
* SERVER_PROTOCOL : HTTP/1.1
* SERVER_SOFTWARE : puma 4.3.1 Mysterious Traveller
* action_controller.instance : #<HomeController:0x00007f80820bf040>
* action_dispatch.authenticated_encrypted_cookie_salt : authenticated encrypted cookie
* action_dispatch.backtrace_cleaner : #<Rails::BacktraceCleaner:0x00007f808c109230>
* action_dispatch.content_security_policy :
* action_dispatch.content_security_policy_nonce_generator:
* action_dispatch.content_security_policy_report_only : false
* action_dispatch.cookies_digest :
* action_dispatch.cookies_rotations : #<ActiveSupport::Messages::RotationConfiguration:0x000055c4ff8b6a68>
* action_dispatch.cookies_serializer : json
* action_dispatch.encrypted_cookie_cipher :
* action_dispatch.encrypted_cookie_salt : encrypted cookie
* action_dispatch.encrypted_signed_cookie_salt : signed encrypted cookie
* action_dispatch.http_auth_salt : http authentication
* action_dispatch.key_generator : #<ActiveSupport::CachingKeyGenerator:0x000055c5048f55b0>
* action_dispatch.logger : #<ActiveSupport::Logger:0x000055c503ba0d60>
* action_dispatch.parameter_filter : [:password]
* action_dispatch.redirect_filter : []
* action_dispatch.remote_ip : x.x.x.x
* action_dispatch.request.accepts : [#<Mime::Type:0x000055c4fffb6908 #synonyms=["application/xhtml+xml"], #symbol=:html, #string="text/html", #hash=-2972404158444904653>]
* action_dispatch.request.content_type :
* action_dispatch.request.formats : [#<Mime::Type:0x000055c4fffb6908 #synonyms=["application/xhtml+xml"], #symbol=:html, #string="text/html", #hash=-2972404158444904653>]
* action_dispatch.request.parameters : {"controller"=>"home", "action"=>"index"}
* action_dispatch.request.path_parameters : {:controller=>"home", :action=>"index"}
* action_dispatch.request.query_parameters : {}
* action_dispatch.request.request_parameters : {}
* action_dispatch.request_id : 868e4282-a9e4-4c0d-bd32-5ef99c01229f
* action_dispatch.routes : #<ActionDispatch::Routing::RouteSet:0x000055c503d78ea8>
* action_dispatch.secret_key_base : d810ddadf3d84fc677d85f1209a4e45aae8c4d69aa7f147795536b846c420ca886b0436d1e0da987e4296973069d552094eb3047e2cb2a7419fae21575b19cee
* action_dispatch.secret_token :
* action_dispatch.show_detailed_exceptions : true
* action_dispatch.show_exceptions : true
* action_dispatch.signed_cookie_digest :
* action_dispatch.signed_cookie_salt : signed cookie
* action_dispatch.use_authenticated_cookie_encryption : true
* puma.config : #<Puma::Configuration:0x000055c4ff313340>
* puma.request_body_wait : 0
* puma.socket : #<TCPSocket:0x00007f80740b6e08>
* rack.after_reply : []
* rack.errors : #<IO:0x000055c4fe7d00c8>
* rack.hijack : #<Puma::Client:0x00007f80740b6de0>
* rack.hijack? : true
* rack.input : #<Puma::NullIO:0x000055c4fedd2c50>
* rack.multiprocess : false
* rack.multithread : true
* rack.request.cookie_hash : {"_ga"=>"GA1.3.851066951.1664247544", "_fbp"=>"fb.2.1664247548458.1010494553", "_rack-cas-app_session"=>"17a418e4db5e22d84ee5082d66525685"}
* rack.request.cookie_string : _ga=GA1.3.851066951.1664247544; _fbp=fb.2.1664247548458.1010494553; _rack-cas-app_session=17a418e4db5e22d84ee5082d66525685
* rack.request.query_hash : {}
* rack.request.query_string :
* rack.run_once : false
* rack.session : #<ActionDispatch::Request::Session:0x00007f8083c6c400>
* rack.session.options : #<ActionDispatch::Request::Session::Options:0x00007f8083c6c388>
* rack.tempfiles : []
* rack.url_scheme : http
* rack.version : [1, 3]
-------------------------------
Backtrace:
-------------------------------
app/models/app.rb:4:in `search'
app/controllers/home_controller.rb:14:in `index'
app.rb
class App
class << self
def search(keyword, limit, page, role_id = nil, ms_app_ids = nil)
HTTParty.get(
ROLE_API_URL + API_VERSION + '/apps/search',
headers: HEADERS,
verify: VERIFY,
query: {
keyword: keyword,
limit: limit,
page: page,
role_id: role_id,
ms_app_ids: ms_app_ids
}
).parsed_response
end
def autocomplete(params, role_id = nil, ms_app_ids = nil)
HTTParty.get(
ROLE_API_URL + API_VERSION + '/apps/search',
headers: HEADERS,
verify: VERIFY,
query: {
keyword: params[:term],
role_id: role_id,
ms_app_ids: ms_app_ids
}
).parsed_response
end
end
end
update - 20221216
We have tried call the endpoints directly, without KONG and we got the same error message.
Is it possible the issue on the HTTParty configuration or the HTTParty gem version?

NoMethodError at /calculate undefined method `id' for nil:NilClass in Rails Appilcation

I have inherited a rails application that I am supposed to debug and get up running, but the thing is I am not to familiar with rails. I have done research on the error on here and other places, but I still do not know how to fix this error.
here is the code for my calculate model
class Calculation < ActiveRecord::Base
belongs_to :user
has_many :calculation_expenses, dependent: :delete_all
has_many :user_account_stats, dependent: :delete_all
accepts_nested_attributes_for :calculation_expenses
def self.calculate_for(user, period = 'weeks', periods_count = 5*53 - 1)
user_accounts = {}
checking_ids = []
total_checking = 0
total_expense_per_account = {}
user.user_accounts.each do |ua|
total_expense_per_account[ua.id] = 0
user_accounts[ua.id] = ua.amount
if ua.is_checking?
checking_ids << ua.id
total_checking = total_checking + ua.amount
end
end
monthly = false
monthly = true if period == 'months'
user.user_account_stats.where('calculations.is_monthly = ?', monthly).delete_all
user.calculation_expenses.where('calculations.is_monthly = ?', monthly).delete_all
IncomeStat.where('income_id IN (?)', user.incomes.map(&:id)).delete_all
user.calculations.where(is_monthly: monthly).delete_all
calcs = []
calcs_expenses = []
accounts_stats = []
income_stats = []
left_to_bugdet = []
expenses = user.expenses.to_a
incomes = user.incomes.where(is_system: false).to_a
system_income_id = user.incomes.where(is_system: true).first.id
goals = user.expenses.where(is_goal: true).reorder('rank_of_priority ASC').to_a
goal_ids = goals.map(&:id)
current_goals_balance = {}
current_expenses_total = {}
goal_payments_made = {}
goal_monthly_override = {} #using this for loan payments with extra payed sum
loan_pay_off = {}
expenses_monthly = {}
expenses.each do |expense|
current_expenses_total[expense.id] = 0
expenses_monthly[expense.id] = expense.amount
end
start_dt = Date.today
start_dt += 1 + ((5 - start_dt.wday) % 7)
# firstly we need to calculate all incomes and expenses
for i in 0..periods_count
week_start = start_dt + i.send(period)
week_end = week_start + 1.send(period) - 1.day
total_income = 0
total_expense = 0
current_expenses = {}
scheduled_expenses = {}
expense_per_account = {}
user_accounts.each_pair do |key, amount|
expense_per_account[key] = 0
end
incomes.each do |income| #add incomes
cnt = income.exists_between week_start, week_end
income_amount = cnt * income.amount
total_income = total_income + income_amount
income_stats << [income_amount, income.id]
user_accounts[income.user_account_id] = user_accounts[income.user_account_id] + income_amount
if checking_ids.include? income.user_account_id
total_checking = total_checking + income_amount
end
end
income_stats << [0, system_income_id]
expenses.each do |expense| #substract expenses
cnt = expense.exists_between week_start, week_end
scheduled_expenses[expense.id] = (cnt > 0)
goal_payments_made[expense.id] ||= 0
goal_payments_made[expense.id] = goal_payments_made[expense.id] + cnt
ea = expense.amount
ea = goal_monthly_override[expense.id] unless goal_monthly_override[expense.id].nil?
expense_amount = cnt * ea
if expense.is_loan? && cnt > 0
loan_pay_off[expense.id] ||= 0
if expense.get_debt_sum - loan_pay_off[expense.id] < expense_amount
expense_amount = (expense.get_debt_sum - loan_pay_off[expense.id]) * (1 + expense.interest / Frequency.get_interest_amount(expense.frequency_id) / 100.0)
end
loan_pay_off[expense.id] = loan_pay_off[expense.id] + expense.get_main_part(loan_pay_off[expense.id], expense_amount)
end
if checking_ids.include? expense.user_account_id
total_expense = total_expense + expense_amount
end
user_accounts[expense.user_account_id] = user_accounts[expense.user_account_id] - expense_amount
current_expenses[expense.id] = expense_amount
expense_per_account[expense.user_account_id] = expense_per_account[expense.user_account_id] + expense_amount
if checking_ids.include? expense.user_account_id
total_checking = total_checking - expense_amount
end
current_expenses_total[expense.id] = current_expenses_total[expense.id] + expense_amount
total_expense_per_account[expense.user_account_id] = total_expense_per_account[expense.user_account_id] + expense_amount
end
extra_money = total_checking - user.minimum_safety_level
j = i - 1
while extra_money < 0 && j > 0 do #respect minimum safety level by reducing extra money levels on previous periods
reduce_extra = -extra_money
if calcs[j][5] < reduce_extra
reduce_extra = calcs[j][5]
end
calcs[j][5] = calcs[j][5] - reduce_extra
extra_money = extra_money + reduce_extra
calcs[i]
j = j - 1
end
extra_money = 0 if extra_money < 0
calcs << [week_end, user.id, total_income, total_expense, monthly, extra_money]
current_expenses.each_pair do |expense_id, budgeted|
calcs_expenses << [expense_id, budgeted, nil, current_expenses_total[expense_id], loan_pay_off[expense_id] || 0, scheduled_expenses[expense_id], expenses_monthly[expense_id]]
end
a = [] #temporary save stats
user_accounts.each_pair do |user_account_id, amount|
a << [user_account_id, amount, amount, expense_per_account[user_account_id], nil, total_expense_per_account[user_account_id]]
end
accounts_stats << a
end
extra_payments_data = []
accounts_stats = accounts_stats.map { |a| a }.sum
self.save_data(user, monthly, expenses.size, calcs, calcs_expenses, extra_payments_data, accounts_stats, income_stats)
#find last calculation without extra money
last_zero = Calculation.where(user_id: user.id, is_monthly: monthly, extra_money: 0).reorder('dt DESC').first
## remove local extra money before last zero - we cannot spend them
unless last_zero.nil?
Calculation.where(user_id: user.id, is_monthly: monthly).where('id < ?', last_zero.id).update_all extra_money: 0
# # find an extra money we can spend
em_count = Calculation.where(user_id: user.id, is_monthly: monthly).where('extra_money > 0').count
g = 0
id = 0
while em_count > 0 && g < periods_count - 1 do
calc = Calculation.where(user_id: user.id, is_monthly: monthly).where('extra_money > 0 AND id > ?', id).reorder('extra_money ASC').first
unless calc.nil?
goals.each do |goal|
unless goal.ends_before? calc.dt
ce = calc.calculation_expenses.where(expense_id: goal.id).first
amount = goal.aggressiveness / 100.0 * calc.extra_money
goal_left = goal.get_debt_sum - ce.paid_off
amount = goal_left if goal_left < amount
if amount > 0
ce.update_budgeted ce.budgeted + amount
end
end
end
g = g + 1
puts "#{g} of #{periods_count}"
id = calc.id
#find last calculation without extra money
last_zero = Calculation.where(user_id: user.id, is_monthly: monthly, extra_money: 0).reorder('dt DESC').first
# remove local extra money before last zero - we cannot spend them
Calculation.where(user_id: user.id, is_monthly: monthly).where('id < ?', last_zero.id).update_all extra_money: 0
else
g = periods_count
end
end
end
end
def self.save_data(user, monthly, expenses_count, calcs, calcs_expenses, extra_payments_data, accounts_stats, income_stats, dt = nil)
# write calculations to database
Calculation.import([:dt, :user_id, :total_income, :total_expense, :is_monthly, :extra_money], calcs, validate: false)
# write calculation ids to arrays
if dt.nil?
ids = user.calculations.where(is_monthly: monthly).pluck(:id)
else
ids = user.calculations.where(is_monthly: monthly).where('dt >= ?', dt).pluck(:id)
end
cur_ind = 0
cur_ind2 = 0
cur_ind3 = 0
num = expenses_count
num2 = user.incomes.count
num3 = user.user_accounts.size
ids.each_with_index do |id, ind|
num.times do
calcs_expenses[cur_ind] << ids[ind]
cur_ind = cur_ind + 1
end
num2.times do
income_stats[cur_ind2] << ids[ind]
cur_ind2 = cur_ind2 + 1
end
num3.times do
accounts_stats[cur_ind3] << ids[ind]
cur_ind3 = cur_ind3 + 1
end
end
# write all data with 2 queries
UserAccountStat::import([:user_account_id, :amount, :initial_amount, :budgeted, :actual, :total, :calculation_id], accounts_stats, validate: false)
CalculationExpense::import([:expense_id, :budgeted, :actual, :total, :paid_off, :is_scheduled, :monthly_payment, :calculation_id], calcs_expenses, validate: false)
IncomeStat::import([:amount, :income_id, :calculation_id], income_stats, validate: false)
user.expenses_groups.each do |group|
group.calculate_data
end
end
def as_json(options)
{
id: self.id,
total_income: self.total_income,
total_expense: self.total_expense,
extra_money: self.extra_money,
dt: self.dt
}
end
end
Here is my calculation controller
class CalculationsController < ApplicationController
def index
unless current_user.calculations.any?
redirect_to '/calculate'
end
end
def load
respond_to do |format|
format.json { render json: get_data }
end
end
def calc
Calculation.calculate_for(current_user)
redirect_to calculations_path
end
def update
#calc = current_user.calculation_expenses.where(id: params[:id]).first
#calc.update_actual params[:value]
respond_to do |format|
format.json { render json: get_data }
end
end
def update_budgeted
#calc = current_user.calculation_expenses.where(id: params[:id]).first
#calc.update_budgeted params[:value]
respond_to do |format|
format.json { render json: get_data }
end
end
def group
if params[:id].blank?
#group = ExpensesGroup.create(name: params[:name], user_id: current_user.id)
else
#group = current_user.expenses_groups.where(id: params[:id]).first
unless #group.nil?
#group.update_attribute :name, params[:name]
end
end
end
end
When I run the application locally I can see that the problem is with this line in the calculate_for method in the calculation model
system_income_id = user.incomes.where(is_system: true).first.id
and with this line in the cal method of the calculation control
Calculation.calculate_for(current_user)
Here is the error log from rails console
NoMethodError - undefined method `id' for nil:NilClass:
app/models/calculation.rb:36:in `calculate_for'
app/controllers/calculations_controller.rb:16:in `calc'
actionpack (4.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.3) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.3) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.3) lib/active_support/callbacks.rb:115:in `call'
activesupport (4.2.3) lib/active_support/callbacks.rb:553:in `block (2 levels) in compile'
activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call'
activesupport (4.2.3) lib/active_support/callbacks.rb:88:in `run_callbacks'
actionpack (4.2.3) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.3) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.3) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.3) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.3) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.3) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.3) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.3) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:45:in `serve'
actionpack (4.2.3) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.3) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:821:in `call'
meta_request (0.3.0) lib/meta_request/middlewares /app_request_handler.rb:13:in `call'
rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
meta_request (0.3.0) lib/meta_request/middlewares/headers.rb:16:in `call'
meta_request (0.3.0) lib/meta_request/middlewares /meta_request_handler.rb:13:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.3) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.3) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.3) lib/active_support/callbacks.rb:84:in `run_callbacks'
actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.3) lib/rails/engine.rb:518:in `call'
railties (4.2.3) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
/home/xwattsh/.rbenv/versions/2.2.3/lib/ruby/2.2.0/webrick /httpserver.rb:138:in `service'
/home/xwattsh/.rbenv/versions/2.2.3/lib/ruby/2.2.0/webrick /httpserver.rb:94:in `run'
/home/xwattsh/.rbenv/versions/2.2.3/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
=>This line is not safe:
system_income_id = user.incomes.where(is_system: true).first.id
It will cause an exception when the user have no income where is_system is set to true.
You can either check if the .first is nil or not, or put it in a try/catch block. Either case, it depends on you to handle the case where .first do not exist.
ex.
first_system_income = user.incomes.where(is_system: true).first
if first_system_income.present?
//do your normal stuff here
else
//handle the exception case
end
or (not recommended)
begin
system_income_id = user.incomes.where(is_system: true).first.id
rescue => e
//handle the exception case
puts e
end
On a separate note, that's some serious logic in one method! Maybe some comments or refactor would help, now that you inherited the project :)

no implicit conversion of nil into String (sponsorship )

I am getting the above error and it says that it has to do with the "+". Please note I did not code the below page, but I was told to fix it. If someone could help that would be awesome.
MYMOH Controller
210. def sponsorships
211. dbdc_client.materialize("cv__Recurring_Gift__c")
212. ##gifts =Cv__Recurring_Gift__c.find_all_by_cv__Contact__c(current_user.convio_id)
213. #gifts = Cv__Recurring_Gift__c.query("cv__Contact__c = '" + current_user.convio_id + "' AND Child_Status__c = 'Sponsored' and cv__Recurring_Gift_Status__c='Active'")
214. #account = Contact.find_by_Id(current_user.convio_id)
215. ##old_sponsorships = Child_Sponsorship__c.query("Sponsor__c = '" + current_user.convio_id + "' AND Status__c = 'Open'")
216. #sponsorships = #gifts # + #old_sponsorships
217. unless #sponsorships.nil?
218. #if we find sponsorships
219. #children = []
220. #sponsorships.each do | spons |
221. #photo = nil
222. unless spons.Child__c.nil?
223. #child = Child__c.find_by_Id(spons.Child__c)
224. #photoTest = Picture__c.query("Child__c='" + #child.Id + "' and Primary__c=true").first
225. #photo = #photoTest.Photo__c if #photoTest
226. if #photo.nil?
227. #attachment = Attachment.find_by_ParentId(#child.Id)
228. #photo = "<img src='https://c.na12.content.force.com/servlet/servlet.FileDownload?file=" + #attachment.Id.to_s + "' />" unless #attachment.nil?
end
#set an unused variable to carry the photo url
#child.LastModifiedById = #photo
#add child to array of children
#children << #child
end
end
end
end
FULL TRACE
app/controllers/mymoh_controller.rb:213:in `+'
app/controllers/mymoh_controller.rb:213:in `sponsorships'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/abstract_controller/base.rb:167:in `process_action'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_controller/metal/rendering.rb:10:in `process_action'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:425:in `_run__3687996442544047678__process_action__3216127983448203575__callbacks'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/abstract_controller/callbacks.rb:17:in `process_action'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_controller/metal/rescue.rb:29:in `process_action'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/notifications.rb:123:in `block in instrument'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/notifications.rb:123:in `instrument'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.11/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:23:in `block in process_action'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:353:in `perform_action_with_newrelic_trace'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:22:in `process_action'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/abstract_controller/base.rb:121:in `process'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/abstract_controller/rendering.rb:45:in `process'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_controller/metal.rb:203:in `dispatch'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_controller/metal.rb:246:in `block in action'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:73:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:36:in `call'
vendor/bundle/ruby/2.1.0/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
vendor/bundle/ruby/2.1.0/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
vendor/bundle/ruby/2.1.0/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:601:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/rack/browser_monitoring.rb:23:in `traced_call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/exception_notification-4.0.0/lib/exception_notification/rack.rb:28:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/etag.rb:23:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/conditionalget.rb:25:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/head.rb:14:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/flash.rb:242:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210:in `context'
vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/cookies.rb:341:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.11/lib/active_record/query_cache.rb:64:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `_run__790379348702901205__call__4407048364405463113__callbacks'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/rack/logger.rb:32:in `call_app'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/rack/logger.rb:16:in `block in call'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/tagged_logging.rb:22:in `tagged'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/rack/logger.rb:16:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/request_id.rb:22:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.11/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.11/lib/action_dispatch/middleware/static.rb:62:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
vendor/bundle/ruby/2.1.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch'
vendor/bundle/ruby/2.1.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup'
vendor/bundle/ruby/2.1.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
vendor/bundle/ruby/2.1.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-timeout-0.2.4/lib/rack/timeout.rb:108:in `call'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/engine.rb:479:in `call'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/application.rb:223:in `call'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/rack/log_tailer.rb:17:in `call'
vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:86:in `block in pre_process'
vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `catch'
vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `pre_process'
vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:53:in `process'
vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:39:in `receive_data'
vendor/bundle/ruby/2.1.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run_machine'
vendor/bundle/ruby/2.1.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run'
vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/backends/base.rb:73:in `start'
vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/server.rb:162:in `start'
vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/handler/thin.rb:13:in `run'
vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/server.rb:268:in `start'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/commands/server.rb:70:in `start'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/commands.rb:55:in `block in <top (required)>'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/commands.rb:50:in `tap'
vendor/bundle/ruby/2.1.0/gems/railties-3.2.11/lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
#pref is not declared as a string just by assigning it " ".
Try this:
preferences = String.new
if !params[:prefgirl].nil?
preferences = preferences + "Girl,"
end
.
.
.
#preferences = preferences
Thanks for posting the code. If the stack trace is pointing to the right place, the error is here, where you're building a string like this:
"cv__Contact__c = '" + current_user.convio_id + "' AND Child_Status__c = 'Sponsored' and cv__Recurring_Gift_Status__c='Active'"
If current_user.convio_id is nil, you will get the error you cite. You should think about either guarding against current_user.convio_id being nil, or how that query should be built if it is.
A more Rubyish way to build that string, by the way, is using interpolation:
"cv__Contact__c = '#{current_user.convio_id}' AND Child_Status__c = 'Sponsored' and cv__Recurring_Gift_Status__c='Active'"
The error specifically means that current_user.convio_id is nil, and Ruby will not convert nil to a string without being told directly to. The + concatenates strings if the object on the left side is a string.
It seems that your whole sponsorship action depends on the user having a convio_id If that is a field that all users should have you should add a not null attribute to it, and go through and add one to all that don't have one currently.
If a convio_id is an optional thing you should check at the beginning of the action if they have one ex-
def sponsorships
if current_user.convio_id.nil?
flash[:convio_id] = "User has no Convio ID" # optional message saying why we're redirecting
redirect_to <somewhere else> and return
end
<rest of the code here>
To add a field as required in Ruby, ignoring the database, you would need to add this line in to your model, probably app/models/user.rb
class User < ActiveRecord::Base
...
validates :convio_id, presence: true
...
end
This will make it so all users created through the website must have a convio_id to be valid and saved.

Weird routing request throwing NoMethodError "undefined method `merge' for nil:NilClass"

Hi I have a VPS Ubuntu 10.04 setup using nginx, capistrano, varnish, Phusion Passenger and Rails. Once in awhile I get a weird routing request looking for the route:
http://localhost/cgi-bin/php/cgin/php?%2D%64+%61%6C%75%6F%6E+%2D%64+%6D%6F%64+%2D%64+%73%75%68%6F%6E%3D%6F%6E+%2D%64+%75%6E%63%74%73%3D%22%22+%2D%64+%64%6E%65+%2D%64+%61%75%74%6F%5F%70%72%%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%74%5F%3D%30+%2D%64+%75%74+%2D%6E
This causes the Rails to throw a NoMethodError exception. What could be causing this request from occurring on the server?
Here is the stack trace I get from the server:
A NoMethodError occurred in errors#routing:
undefined method `merge' for nil:NilClass
rack (1.3.10) lib/rack/request.rb:202:in `params'
-------------------------------
Request:
-------------------------------
* URL : http://localhost/cgi-bin/php/cgin/php?%2D%64+%61%6C%75%6F%6E+%2D%64+%6D%6F%64+%2D%64+%73%75%68%6F%6E%3D%6F%6E+%2D%64+%75%6E%63%74%73%3D%22%22+%2D%64+%64%6E%65+%2D%64+%61%75%74%6F%5F%70%72%%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%74%5F%3D%30+%2D%64+%75%74+%2D%6E
* IP address: 127.0.0.1
* Parameters: {"controller"=>"errors", "action"=>"routing", "a"=>"cgi-bin/php/cgin/php"}
* Rails root: /home/deploy/application.com/releases/20131117065231
* Timestamp : 2013-12-06 06:19:02 UTC
-------------------------------
Session:
-------------------------------
* session id: nil
* data: {}
-------------------------------
Environment:
-------------------------------
* CONTENT_LENGTH : 1
* CONTENT_TYPE : text/html
* DOCUMENT_ROOT : /home/deploy/application.com/current/public
* HTTPS : off
* HTTP_HOST : localhost
* HTTP_X_FORWARDED_PROTO : http
* HTTP_X_VARNISH : 340799594
* ORIGINAL_FULLPATH : /cgi-bin/php/cgin/php?%2D%64+%61%6C%75%6F%6E+%2D%64+%6D%6F%64+%2D%64+%73%75%68%6F%6E%3D%6F%6E+%2D%64+%75%6E%63%74%73%3D%22%22+%2D%64+%64%6E%65+%2D%64+%61%75%74%6F%5F%70%72%%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%74%5F%3D%30+%2D%64+%75%74+%2D%6E
* PASSENGER_APP_TYPE : rack
* PASSENGER_CONNECT_PASSWORD : [FILTERED]
* PASSENGER_ENV : production
* PASSENGER_MIN_INSTANCES : 1
* PATH_INFO : /cgi-bin/php/cgin/php
* QUERY_STRING : %2D%64+%61%6C%75%6F%6E+%2D%64+%6D%6F%64+%2D%64+%73%75%68%6F%6E%3D%6F%6E+%2D%64+%75%6E%63%74%73%3D%22%22+%2D%64+%64%6E%65+%2D%64+%61%75%74%6F%5F%70%72%%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%74%5F%3D%30+%2D%64+%75%74+%2D%6E
* REMOTE_ADDR : 127.0.0.1
* REMOTE_PORT : 34005
* REQUEST_METHOD : POST
* REQUEST_URI : /cgi-bin/php/cgin/php?%2D%64+%61%6C%75%6F%6E+%2D%64+%6D%6F%64+%2D%64+%73%75%68%6F%6E%3D%6F%6E+%2D%64+%75%6E%63%74%73%3D%22%22+%2D%64+%64%6E%65+%2D%64+%61%75%74%6F%5F%70%72%%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%74%5F%3D%30+%2D%64+%75%74+%2D%6E
* SCGI : 1
* SCRIPT_NAME :
* SERVER_ADDR : 127.0.0.1
* SERVER_NAME : localhost
* SERVER_PORT : 8080
* SERVER_PROTOCOL : HTTP/1.1
* SERVER_SOFTWARE : nginx/1.4.3
* action_controller.instance : errors#routing
* action_dispatch.cookies : #<ActionDispatch::Cookies::CookieJar:0xe348290>
* action_dispatch.parameter_filter : [:password, /RAW_POST_DATA/]
* action_dispatch.remote_ip : 127.0.0.1
* action_dispatch.request.content_type : text/html
* action_dispatch.request.parameters : {"controller"=>"errors", "action"=>"routing", "a"=>"cgi-bin/php/cgin/php"}
* action_dispatch.request.path_parameters : {:controller=>"errors", :action=>"routing", :a=>"cgi-bin/php/cgin/php"}
* action_dispatch.request.query_parameters : {}
* action_dispatch.request.request_parameters : {}
* action_dispatch.request.unsigned_session_cookie: {}
* action_dispatch.routes : #<ActionDispatch::Routing::RouteSet:0xa0b7d40>
* action_dispatch.secret_token : 17975cc9cf1bfec1badfa83becc730a52221e2f5fe23cc8cec56361d311069f25e7daee6e842e1f149a4e29b0014127cc0efb675173ed2c828c8a0846b1eaf4b
* action_dispatch.show_exceptions : true
* exception_notifier.options : {:sender_address=>"\"exception notifier\" <info#application.com>", :exception_recipients=>["admin#application.com"], :email_prefix=>"[Exception] ", :email_format=>:text, :sections=>["request", "session", "environment", "backtrace"], :background_sections=>["backtrace", "data"], :verbose_subject=>true, :normalize_subject=>false, :template_path=>"exception_notifier", :smtp_settings=>nil, :ignore_exceptions=>["ActiveRecord::RecordNotFound", "AbstractController::ActionNotFound", "ActionController::RoutingError"], :ignore_crawlers=>[], :ignore_if=>#<Proc:0xba1781c#/usr/local/lib/ruby/gems/1.9.1/gems/exception_notification-3.0.0/lib/exception_notifier.rb:36 (lambda)>}
* rack-cache.allow_reload : false
* rack-cache.allow_revalidate : false
* rack-cache.cache_key : Rack::Cache::Key
* rack-cache.default_ttl : 0
* rack-cache.entitystore : rails:/
* rack-cache.ignore_headers : ["Set-Cookie"]
* rack-cache.metastore : rails:/
* rack-cache.private_headers : ["Authorization", "Cookie"]
* rack-cache.storage : #<Rack::Cache::Storage:0xac65cb4>
* rack-cache.use_native_ttl : false
* rack-cache.verbose : true
* rack.errors : #<IO:0x9949ce8>
* rack.hijack : #<Proc:0xef66c48#/usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.23/lib/phusion_passenger/rack/thread_handler_extension.rb:69 (lambda)>
* rack.hijack? : true
* rack.input : #<PhusionPassenger::Utils::TeeInput:0xef66dec>
* rack.multiprocess : true
* rack.multithread : false
* rack.request.cookie_hash : {}
* rack.request.query_string : %2D%64+%61%6C%75%6F%6E+%2D%64+%6D%6F%64+%2D%64+%73%75%68%6F%6E%3D%6F%6E+%2D%64+%75%6E%63%74%73%3D%22%22+%2D%64+%64%6E%65+%2D%64+%61%75%74%6F%5F%70%72%%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%74%5F%3D%30+%2D%64+%75%74+%2D%6E
* rack.run_once : false
* rack.session : {}
* rack.session.options : {:key=>"_application_session", :path=>"/", :domain=>:all, :expire_after=>10 years, :secure=>false, :httponly=>true, :defer=>false, :renew=>false, :http_only=>true, :secret=>"f6ecedcf6396859ce6b32656f0678419f72afe61ecc15707085abf80c3d8", :coder=>#<Rack::Session::Cookie::Base64::Marshal:0xbb31090>, :id=>nil}
* rack.url_scheme : http
* rack.version : [1, 2]
* warden : Warden::Proxy:125517500 #config={:default_scope=>:user, :scope_defaults=>{}, :default_strategies=>{:user=>[:rememberable, :database_authenticatable]}, :intercept_401=>false, :failure_app=>#<Devise::Delegator:0xb02dbd0>}
* Process: 9625
* Server : server_name
-------------------------------
Backtrace:
-------------------------------
rack (1.3.10) lib/rack/request.rb:202:in `params'
newrelic_rpm (3.5.5.38) lib/new_relic/rack/error_collector.rb:15:in `rescue in call'
newrelic_rpm (3.5.5.38) lib/new_relic/rack/error_collector.rb:8:in `call'
newrelic_rpm (3.5.5.38) lib/new_relic/rack/browser_monitoring.rb:12:in `call'
exception_notification (3.0.0) lib/exception_notifier.rb:40:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.1.12) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.10) lib/rack/etag.rb:23:in `call'
rack (1.3.10) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.1.12) lib/action_dispatch/middleware/head.rb:14:in `call'
remotipart (1.0.2) lib/remotipart/middleware.rb:30:in `call'
actionpack (3.1.12) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.12) lib/action_dispatch/middleware/flash.rb:243:in `call'
rack (1.3.10) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.10) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.12) lib/action_dispatch/middleware/cookies.rb:331:in `call'
activerecord (3.1.12) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.1.12) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.12) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.12) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.12) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.12) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
rack (1.3.10) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.12) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.12) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.12) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.10) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.10) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.12) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.10) lib/rack/lock.rb:15:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:143:in `pass'
rack-cache (1.2) lib/rack/cache/context.rb:152:in `rescue in invalidate'
rack-cache (1.2) lib/rack/cache/context.rb:149:in `invalidate'
rack-cache (1.2) lib/rack/cache/context.rb:71:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.1.12) lib/rails/engine.rb:456:in `call'
railties (3.1.12) lib/rails/application.rb:143:in `call'
railties (3.1.12) lib/rails/railtie/configurable.rb:30:in `method_missing'
passenger (4.0.23) lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
passenger (4.0.23) lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
passenger (4.0.23) lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
passenger (4.0.23) lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'

Omniauth + Google + Faraday + Behind the proxy = how setup proxy?

My production server is Ubuntu 12.
I'm using Devise + OmniAuth to handle the Google authentication.
But when Google returns a control to my application I get an error "Network is unreachable".
I assume it's because of server is behind the proxy.
Here's error description:
-------------------------------
Request:
-------------------------------
* URL : http://efiling.uipv.org/users/auth/google_oauth2/callback?state=f4eaca9fbed2a77c0baac50cdbdccab7eee671179bb8fc43&code=4/YRcyYZzkrfNh8mEBbenxaxyx5EjN.4snirEA-93MXOl05ti8ZT3a9mXdIcgI
* IP address: 213.160.144.239
* Parameters: {"state"=>"f4eaca9fbed2a77c0baac50cdbdccab7eee671179bb8fc43", "code"=>"4/YRcyYZzkrfNh8mEBbenxaxyx5EjN.4snirEA-93MXOl05ti8ZT3a9mXdIcgI"}
* Rails root: /home/test/efiling2
* Timestamp : 2012-08-14 11:22:27 +0300
-------------------------------
Session:
-------------------------------
* session id: "5b45534889547514b01f59e39f21f74a"
* data: {"session_id"=>"5b45534889547514b01f59e39f21f74a",
"_csrf_token"=>"GJAFgiVO3zd/INIW6DqDh/VYGlvoZ8WuEKAX1HseJwA="}
-------------------------------
Environment:
-------------------------------
* CONTENT_LENGTH : 0
* DOCUMENT_ROOT : /home/test/efiling2/public
* HTTP_ACCEPT : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
* HTTP_ACCEPT_ENCODING : gzip, deflate
* HTTP_ACCEPT_LANGUAGE : ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3
* HTTP_CACHE_CONTROL : max-age=0
* HTTP_CONNECTION : keep-alive
* HTTP_COOKIE : _eFiling2_session=BAh7CkkiD3Nlc3Npb25faWQGOgZFRiIlNWI0NTUzNDg4OTU0NzUxNGIwMWY1OWUzOWYyMWY3NGFJIhBfY3NyZl90b2tlbgY7AEZJIjFHSkFGZ2lWTzN6ZC9JTklXNkRxRGgvVllHbHZvWjhXdUVLQVgxSHNlSndBPQY7AEZJIhRvbW5pYXV0aC5wYXJhbXMGOwBGewBJIhRvbW5pYXV0aC5vcmlnaW4GOwBGIidodHRwOi8vZWZpbGluZy51aXB2Lm9yZy8%2FbG9jYWxlPXVrSSITb21uaWF1dGguc3RhdGUGOwBGIjVmNGVhY2E5ZmJlZDJhNzdjMGJhYWM1MGNkYmRjY2FiN2VlZTY3MTE3OWJiOGZjNDM%3D--08b5e8bcf347ac5c845922cbf85f31a24907c100
* HTTP_HOST : efiling.uipv.org
* HTTP_USER_AGENT : Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1
* HTTP_VIA : 1.1 proxy.ukrpatent.org (squid/3.1.19)
* HTTP_X_FORWARDED_FOR : 10.11.10.56
* PASSENGER_APP_SPAWNER_IDLE_TIME : -1
* PASSENGER_APP_TYPE : rack
* PASSENGER_CONNECT_PASSWORD : [FILTERED]
* PASSENGER_DEBUGGER : false
* PASSENGER_ENVIRONMENT : development
* PASSENGER_FRAMEWORK_SPAWNER_IDLE_TIME : -1
* PASSENGER_FRIENDLY_ERROR_PAGES : true
* PASSENGER_GROUP :
* PASSENGER_MAX_REQUESTS : 0
* PASSENGER_MIN_INSTANCES : 1
* PASSENGER_SHOW_VERSION_IN_HEADER : true
* PASSENGER_SPAWN_METHOD : smart-lv2
* PASSENGER_USER :
* PASSENGER_USE_GLOBAL_QUEUE : true
* PATH_INFO : /users/auth/google_oauth2/callback
* QUERY_STRING : state=f4eaca9fbed2a77c0baac50cdbdccab7eee671179bb8fc43&code=4/YRcyYZzkrfNh8mEBbenxaxyx5EjN.4snirEA-93MXOl05ti8ZT3a9mXdIcgI
* REMOTE_ADDR : 213.160.144.239
* REMOTE_PORT : 62175
* REQUEST_METHOD : GET
* REQUEST_URI : /users/auth/google_oauth2/callback?state=f4eaca9fbed2a77c0baac50cdbdccab7eee671179bb8fc43&code=4/YRcyYZzkrfNh8mEBbenxaxyx5EjN.4snirEA-93MXOl05ti8ZT3a9mXdIcgI
* SCGI : 1
* SCRIPT_NAME :
* SERVER_ADDR : 10.10.18.3
* SERVER_NAME : efiling.uipv.org
* SERVER_PORT : 80
* SERVER_PROTOCOL : HTTP/1.1
* SERVER_SOFTWARE : nginx/1.2.2
* UNION_STATION_SUPPORT : false
* _ : _
* action_dispatch.cookies : {"_eFiling2_session"=>"BAh7CkkiD3Nlc3Npb25faWQGOgZFRiIlNWI0NTUzNDg4OTU0NzUxNGIwMWY1OWUzOWYyMWY3NGFJIhBfY3NyZl90b2tlbgY7AEZJIjFHSkFGZ2lWTzN6ZC9JTklXNkRxRGgvVllHbHZvWjhXdUVLQVgxSHNlSndBPQY7AEZJIhRvbW5pYXV0aC5wYXJhbXMGOwBGewBJIhRvbW5pYXV0aC5vcmlnaW4GOwBGIidodHRwOi8vZWZpbGluZy51aXB2Lm9yZy8/bG9jYWxlPXVrSSITb21uaWF1dGguc3RhdGUGOwBGIjVmNGVhY2E5ZmJlZDJhNzdjMGJhYWM1MGNkYmRjY2FiN2VlZTY3MTE3OWJiOGZjNDM=--08b5e8bcf347ac5c845922cbf85f31a24907c100"}
* action_dispatch.parameter_filter : [:password, :efile, /RAW_POST_DATA/]
* action_dispatch.remote_ip : 213.160.144.239
* action_dispatch.request.content_type :
* action_dispatch.request.parameters : {"state"=>"f4eaca9fbed2a77c0baac50cdbdccab7eee671179bb8fc43", "code"=>"4/YRcyYZzkrfNh8mEBbenxaxyx5EjN.4snirEA-93MXOl05ti8ZT3a9mXdIcgI"}
* action_dispatch.request.path_parameters : {}
* action_dispatch.request.query_parameters : {"state"=>"f4eaca9fbed2a77c0baac50cdbdccab7eee671179bb8fc43", "code"=>"4/YRcyYZzkrfNh8mEBbenxaxyx5EjN.4snirEA-93MXOl05ti8ZT3a9mXdIcgI"}
* action_dispatch.request.request_parameters : {}
* action_dispatch.request.unsigned_session_cookie: {"session_id"=>"5b45534889547514b01f59e39f21f74a", "_csrf_token"=>"GJAFgiVO3zd/INIW6DqDh/VYGlvoZ8WuEKAX1HseJwA=", "omniauth.params"=>{}, "omniauth.origin"=>"http://efiling.uipv.org/?locale=uk", "omniauth.state"=>"f4eaca9fbed2a77c0baac50cdbdccab7eee671179bb8fc43"}
* action_dispatch.secret_token : f7fa3943c0fc9f3b40a9bc5b0260fa43979de183fc338c08ec96277d6aeab1ce7973c188f93e978d4a513a08d871888520f41671d06a15315ffc6c3d43a1abfa
* action_dispatch.show_exceptions : true
* exception_notifier.options : {:sender_address=>"\"Efiling\" <alex_drobazko#uipv.org>", :exception_recipients=>["drobazko#gmail.com"], :email_prefix=>"[Efiling Error Report] ", :sections=>["request", "session", "environment", "backtrace"], :background_sections=>["backtrace", "data"], :verbose_subject=>true, :normalize_subject=>false, :ignore_exceptions=>["ActiveRecord::RecordNotFound", "AbstractController::ActionNotFound", "ActionController::RoutingError"], :ignore_crawlers=>[], :ignore_if=>#<Proc:0xa55f0b4#/home/test/.rvm/gems/ruby-1.9.3-p194/gems/exception_notification-2.6.1/lib/exception_notifier.rb:30 (lambda)>}
* omniauth.origin : http://efiling.uipv.org/?locale=uk
* omniauth.params : {}
* omniauth.strategy : #<OmniAuth::Strategies::GoogleOauth2:0xafdbca4>
* rack.errors : #<IO:0x9a598f4>
* rack.input : #<PhusionPassenger::Utils::RewindableInput:0xafc2718>
* rack.multiprocess : true
* rack.multithread : false
* rack.request.cookie_hash : {"_eFiling2_session"=>"BAh7CkkiD3Nlc3Npb25faWQGOgZFRiIlNWI0NTUzNDg4OTU0NzUxNGIwMWY1OWUzOWYyMWY3NGFJIhBfY3NyZl90b2tlbgY7AEZJIjFHSkFGZ2lWTzN6ZC9JTklXNkRxRGgvVllHbHZvWjhXdUVLQVgxSHNlSndBPQY7AEZJIhRvbW5pYXV0aC5wYXJhbXMGOwBGewBJIhRvbW5pYXV0aC5vcmlnaW4GOwBGIidodHRwOi8vZWZpbGluZy51aXB2Lm9yZy8/bG9jYWxlPXVrSSITb21uaWF1dGguc3RhdGUGOwBGIjVmNGVhY2E5ZmJlZDJhNzdjMGJhYWM1MGNkYmRjY2FiN2VlZTY3MTE3OWJiOGZjNDM=--08b5e8bcf347ac5c845922cbf85f31a24907c100"}
* rack.request.cookie_string : _eFiling2_session=BAh7CkkiD3Nlc3Npb25faWQGOgZFRiIlNWI0NTUzNDg4OTU0NzUxNGIwMWY1OWUzOWYyMWY3NGFJIhBfY3NyZl90b2tlbgY7AEZJIjFHSkFGZ2lWTzN6ZC9JTklXNkRxRGgvVllHbHZvWjhXdUVLQVgxSHNlSndBPQY7AEZJIhRvbW5pYXV0aC5wYXJhbXMGOwBGewBJIhRvbW5pYXV0aC5vcmlnaW4GOwBGIidodHRwOi8vZWZpbGluZy51aXB2Lm9yZy8%2FbG9jYWxlPXVrSSITb21uaWF1dGguc3RhdGUGOwBGIjVmNGVhY2E5ZmJlZDJhNzdjMGJhYWM1MGNkYmRjY2FiN2VlZTY3MTE3OWJiOGZjNDM%3D--08b5e8bcf347ac5c845922cbf85f31a24907c100
* rack.request.query_hash : {"state"=>"f4eaca9fbed2a77c0baac50cdbdccab7eee671179bb8fc43", "code"=>"4/YRcyYZzkrfNh8mEBbenxaxyx5EjN.4snirEA-93MXOl05ti8ZT3a9mXdIcgI"}
* rack.request.query_string : state=f4eaca9fbed2a77c0baac50cdbdccab7eee671179bb8fc43&code=4/YRcyYZzkrfNh8mEBbenxaxyx5EjN.4snirEA-93MXOl05ti8ZT3a9mXdIcgI
* rack.run_once : false
* rack.session : {"session_id"=>"5b45534889547514b01f59e39f21f74a", "_csrf_token"=>"GJAFgiVO3zd/INIW6DqDh/VYGlvoZ8WuEKAX1HseJwA="}
* rack.session.options : {:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :id=>"5b45534889547514b01f59e39f21f74a"}
* rack.url_scheme : http
* rack.version : [1, 0]
* warden : Warden::Proxy:92171780 #config={:default_scope=>:user, :scope_defaults=>{}, :default_strategies=>{:user=>[:rememberable, :database_authenticatable]}, :intercept_401=>false, :failure_app=>#<Devise::Delegator:0xbf7cb04>}
* Process: 31617
* Server : STORK
-------------------------------
Backtrace:
-------------------------------
/home/test/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:762:in `initialize'
/home/test/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:762:in `open'
/home/test/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
/home/test/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
/home/test/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
/home/test/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:762:in `connect'
/home/test/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
/home/test/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:744:in `start'
/home/test/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1284:in `request'
rest-client (1.6.7) lib/restclient/net_http_ext.rb:51:in `request'
faraday (0.8.2) lib/faraday/adapter/net_http.rb:73:in `perform_request'
faraday (0.8.2) lib/faraday/adapter/net_http.rb:36:in `call'
faraday (0.8.2) lib/faraday/request/url_encoded.rb:14:in `call'
faraday (0.8.2) lib/faraday/connection.rb:226:in `run_request'
oauth2 (0.8.0) lib/oauth2/client.rb:88:in `request'
oauth2 (0.8.0) lib/oauth2/client.rb:131:in `get_token'
oauth2 (0.8.0) lib/oauth2/strategy/auth_code.rb:29:in `get_token'
omniauth-oauth2 (1.1.0) lib/omniauth/strategies/oauth2.rb:100:in `build_access_token'
omniauth-oauth2 (1.1.0) lib/omniauth/strategies/oauth2.rb:75:in `callback_phase'
omniauth (1.1.0) lib/omniauth/strategy.rb:219:in `callback_call'
omniauth (1.1.0) lib/omniauth/strategy.rb:175:in `call!'
omniauth (1.1.0) lib/omniauth/strategy.rb:157:in `call'
sass (3.1.20) lib/sass/plugin/rack.rb:54:in `call'
exception_notification (2.6.1) lib/exception_notifier.rb:34:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.5) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.9) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.9) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.5) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.9) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.5) lib/rack/lock.rb:13:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.5) lib/rack/lock.rb:13:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.9) lib/rails/application.rb:168:in `call'
railties (3.0.9) lib/rails/application.rb:77:in `method_missing'
passenger (3.0.14) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
passenger (3.0.14) lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request'
passenger (3.0.14) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
passenger (3.0.14) lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
passenger (3.0.14) lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
passenger (3.0.14) lib/phusion_passenger/utils.rb:470:in `safe_fork'
passenger (3.0.14) lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
passenger (3.0.14) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.14) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.14) lib/phusion_passenger/abstract_server.rb:180:in `start'
passenger (3.0.14) lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
passenger (3.0.14) lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
passenger (3.0.14) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
passenger (3.0.14) lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
passenger (3.0.14) lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
<internal:prelude>:10:in `synchronize'
passenger (3.0.14) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (3.0.14) lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
passenger (3.0.14) lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
passenger (3.0.14) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
passenger (3.0.14) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.14) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.14) helper-scripts/passenger-spawn-server:99:in `<main>'
As you can see faraday can't reach network connection.
How Can I setup faraday or maybe rest_client to use Proxy settings?
Thanks in advance.
I have solved problem by using monkey patching Oauth2.
require 'faraday'
module OAuth2
# The OAuth2::Client class
class Client
# The Faraday connection object
def connection
options[:connection_opts].merge!({:proxy => 'http://10.10.16.8:3128'})
#connection ||= begin
conn = Faraday.new(site, options[:connection_opts])
conn.build do |b|
options[:connection_build].call(b)
end if options[:connection_build]
conn
end
end
end
end
Here is a better solution :
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, 'login', 'password' {
scope: ['userinfo.email'],
access_type: 'online',
client_options: {connection_opts: {proxy: 'http://myproxy:3128'}}
}
end
Put in an initializer
RestClient.proxy = "http://proxy.example.com/"

Resources