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?
Related
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!
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.
As given in RSpec Mock 2.13, I was trying to stub execute method of ActiveRecord like this,
allow(ActiveRecord::Base.connection).to receive(:execute).and_return(assigments)
I got this error
Failure/Error: allow(ActiveRecord::Base.connection).to receive(:execute).and_return(assigments)
NoMethodError:
undefined method `allow' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007fd8c1501648>
However, I used the older syntax and it worked without any hiccups.
ActiveRecord::Base.connection.should_receive(:execute).and_return(assigments)
How to i call this with RSpec 2 and above versions?
Error:
undefined method `author' for nil:NilClass
In my helper:
def last_updated(group)
g = group.last_updated_version
debugger
g.author.name
end
If I let my last_updated(group) function return group.last_updated_version, the view prints out my object as expected:
#<Assets::Version:0x0000000747af48>
And using the debugger at the point shown above, I can pull out the name
(rdb:1) g.author.name
"Administrator"
But returning group.last_updated_version.author.name results in the error.
Can anyone tell me why group.last_updated_version seems to return my object, but group.last_updated_version.author gives me the nil:NilClass error?
Sorry, silly problem. The helper last_updated() is used in a loop. My method last_updated_version returned nil for some of the group objects it was passed, but not the first. The debugger obviously stops on the first, so it worked in the debugger, but then broke on groups passed after that.
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.