undefined method `[]' for true:TrueClass - ruby-on-rails

I am getting undefined method [] for true:TrueClass error while running the rake task in acts_as_recommendable plugin. The error points to the following line.
items = options[:on_class].find(:all).collect(&:id)
Can someone please tell what am i doing incorrectly.

options is probably defined as true. We can't really know why without more information.

Related

Global error handler for specific case. Undefined method 'public_url'

ruby '2.5.1'
rails '5.1.7'
My project is for sound management. All uploaded files are in the cloud storage - sounds/sound images/album images and etc.
But some files on cloud storage are absent. And for following code in view:
.row
- #sounds.each do |sound|
.col-md-2
.play{ "image-src": "#{sound.image.url(:small)}", style: "background: url(#{sound.image.url(:small)});" }
I get following error:
ActionView::Template::Error (undefined method `public_url' for nil:NilClass)
There are a lot of such cycles (#sounds.each) in the project, so I would not want to rewrite each one.
How to write an error handler for such case? So that in absence of files in storage, sound is skipped.
Maybe there is a way to write code in application_controller.rb or something similar?
I use gem 'carrierwave-google-storage' for images and gem 'google-cloud-storage' for attachment.
It seems that there are some cases where the error ActionView::Template::Error (undefined method `public_url' for nil:NilClass) occurs.
Looking on the Community, it seems that there are some options/ways that can fix this error and it would depend on the way that your code and application is configured. For this reason, I would recommend you to take a look at the following posts and answers, to check if they help you. :)
ActionView::Template::Error: ActionView::Template::Error: undefined method `[]' for nil:NilClass
Railstutorial ActionView::Template::Error: undefined method `email' for nil:NilClass
Ruby on rails : undefined method `map' for nil:NilClass , what causes this? when i add record to table
Let me know if the information helped you!

Rails Fixtures Undefined Method

I am getting an error:
NoMethodError: undefined method `cards' for
V1::CardsControllerTest:0x00000007c17238
when I am making the following call in an integration test:
card = cards(:one)
even though I have defined the fixture 'Cards'.
Does anyone have an idea as to why this is happening?

Ruby extract-testcases.rb:172:in `<main>': undefined method `keys' for nil:NilClass (NoMethodError)

I am new to ruby. How can I fix this error
This is the 172 line
us_headers = all_subtasks.first.keys
Here is the link to the code Snippet.
keys is a method of Hash class. This error occurs because first returns nil. So, all_subtasks returns an empty array, [].

NoMethodError: undefined method `get' for #<Class:0xc3ba52c>

I have a project totally an api one returning json response. I have an affiliation table associated with other information. All information in my tables is being fetched through rake task. Now the issue is, the project was running fine but not now when I run a rake task it gives an error in .get method as such
NoMethodError: undefined method `get' for #<Class:0xc3ba52c>
/home/munam/.rvm/gems/ruby-2.1.4/gems/activerecord-4.1.6/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
Here I have used it :
#affiliation = Affiliation.get('my_key')
If I change this to
#affiliation = Affiliation.find_by_key('my_key')
It works fine. But unfortunately I do not have access rights to change in it. Moreover I do not understand why has that method stopped working just at a sudden.
I read about this over here:
http://api.rubyonrails.org/v3.2.1/classes/ActiveResource/CustomMethods.html#method-c-get
Can I not make it work some other way:
I really need this integration to work properly. I will be really thankful if someone helps.

Stripe RoR - undefined method `encoding' for 1:Fixnum

So I have an if statement. If a customer exists return false. I was trying with an actual customer id but it was throwing an error, I replaced it with a 1. Still getting that error.
if Stripe::Customer.retrieve(1)
throws
undefined method `encoding' for 1:Fixnum
link to the api :
https://stripe.com/docs/api#retrieve_customer
All I had to do was
require "stripe"
... :|
Please check the https://stripe.com/docs/api/ruby#customers
There you can find that, in attributes it takes
id: string
So the code should be
#Stripe::Customer.retrieve({CUSTOMER_ID})
Stripe::Customer.retrieve(1.to_s)
Hope it will work.

Resources