ActionController : undefined method action_name for nil - ruby-on-rails

I get this error arbitrarily during certain actions in my application. I feel this error is due to #app.call(env) in one of my middlewares.
NoMethodError (undefined method `action_name' for nil:NilClass):
vendor/cache/ruby/2.1.0/gems/actionpack-3.2.22/lib/action_controller/caching/sweeping.rb:84:in `callback'
vendor/cache/ruby/2.1.0/gems/actionpack-3.2.22/lib/action_controller/caching/sweeping.rb:59:in `before'
vendor/cache/ruby/2.1.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:325:in `around'
Here's the full-trace of exception.
Origin of exception according to trace.
Similar exception has been reported on google forum but I am not able to conclude anything out of it.
Why is this error even raised at first place ?
Any solution to avoid it ?
Trying to reproduce in a confined environment. Have anybody faced such issue and successfully reproduced it ? (Please share)

Related

Rails jbuilder error: ActionView::Template::Error (undefined method

I have a Rails 6 app and we're using jbuilder to define the shape of JSON responses.
Recently, I started getting the following error:
ActionView::Template::Error (undefined method `empty?' for #<Account:0x0000000116743030>):
The stack trace points to this block inside a jbuilder file:
json.account do
json.call(#account, *Account::APP_FIELDS)
json.logo_url #account.logo
end
If I comment out both of the lines inside the block, the error goes away. If I remove either of the lines and leave the other, the error returns. The stack trace just points me to the first line of the block.
What's going on? How do I fix this?
Figured it out!
Higher in the jbuilder file, a partial is included that adds the same account key. This was causing some kind of name collision.
I stumbled on this by temporarily testing with my key renamed accountt and suddenly it worked. That's when I realized it was conflicting name that was causing the issue. I didn't see it because it was in a different file and the error message was confusing. If your jbuilder file is complicated and you think you're running into this same issue, this is an easy way to test.

Issue with Dalli not working as expectd?

I have a simple rails app and I am trying to save and retrieve keys from a memcache box, which was working for a long time unless we started encountering the error below, I have tried debugging this but will need someone to help now
[2015-10-28 12:25:46.649][ERROR] Unexpected exception during Dalli request: NoMethodError: undefined method `<<' for nil:NilClass (pid:58452)
[2015-10-28 12:25:46.649][ERROR] /Users/aupadhyay/.rvm/gems/ruby-2.2.2/gems/celluloid-0.17.2/lib/celluloid/proxy/async.rb:28:in `method_missing'
/Users/aupadhyay/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/core_ext/marshal.rb:6:in `load'
Let me know incase anyone has insights to this ?

NoMethodError using order intermittently

I am getting the following error in a production rails application intermittently
NoMethodError (undefined method `values' on priority:Symbol.):
app/controllers/things_controller.rb:33:in `index'
The offending line looks like this:
#things = Thing.where(:some_column => 'some_value').order(:priority).reverse
Thing is an activerecord model.
The weird thing is, when I restart the application the error disappears. It is only under some strange set of circumstances that this happens (which I can't reproduce in preprod/dev environments).
Has anyone come across something like this before? Can anyone suggest how I would go about diagnosing this bug? The line in question doesn't seem to be the problem (the logs in production also don't show the full stacktrace)
After a length hair pulling session, I discovered that this is due to a bug in rubinius (2.2.10, and 2.2.9). The ActiveRecord query methods where and order both call enumerable#grep internally. After the application has been running for some time, or some unknown conditions are met, this function stops behaving correctly when the array contains symbols.
When a block is given as an argument to the grep function, this block will always be applied to the symbol elements of the array, regardless of the pattern given.
Bug report is here

resque-web: NoMethodError at /failed undefined method `to_yaml'

Resque-web is up and running but when trying to view the failed jobs I get the following error:
NoMethodError at /failed
undefined method `to_yaml' for 3:Fixnum
The stack trace points to a 'to_yaml' call as mentioned in the error, it seems like resque-web is missing a requires. Has anyone else had this problem or know how to solve it?
Note: I'm running this locally on a rails 4 app.
You can see the reason here: https://github.com/resque/resque/issues/1143 -- it boils down to a temporary bug that is fixed, but not released yet. I fixed mine by adding
require 'yaml'
at the top of the server.rb file
note that the server.rb file on my machine was located at:
/usr/local/lib/ruby/gems/2.0.0/gems/resque-1.25.1/lib/resque/server.rb
your location may vary

Why is RSpec/Capybara not showing where errors occured

I'm using Capybara with webkit for my testing, but for some reason when a test fails it shows the error, but not where it actually occurred in the code.
Failures:
1) online shopping - sign up
Failure/Error: page.should have_content 'Payment added successfully'
expected there to be content "Payment added successfully" in "Internal Server Error undefined method `client_id' for #<InvoicePayment:0x007fbd5b834008> WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20) at 127.0.0.1:60324"
# ./spec/requests/online_shopping_spec.rb:140:in `block (2 levels) in <top (required)>'
and when using save_and_open_page it'll just show the error, with no information on where it occured:
Internal Server Error
undefined method `client_id' for #
WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20) at 127.0.0.1:60324
What I'm expecting to see is the line number and function where the error occured:
app/controllers/invoices_controller.rb:30:in `show'
I can't seem to find anything related to this on Google. I'm probably using incorrect nomenclature. Anybody know how to fix this?
Basically capybara does not have a knowledge about the app, since it's running in the different process. You could workaround this problem using this a trick described here https://gist.github.com/1443408
The problem is that the actual page is not rendering because of an error, and instead you are getting an internal server error. So Internal Server Error undefined method... is the content of the page you are testing. RSpec/Capybara can't tell you where it occurred because the test framework only tests what you actually see on the page, and that is exactly what you see (as you confirmed when you ran save_and_open_page).
To track down the error you should look at your rails error log, or the console/terminal where you are running it from. Without more information I can't help you track down the error.
Hope that helps.

Resources