I'm writing testing code for api created by grape in rails. There's an error: undefined method `response_body=' for #
does anyone knows the reason and how to fix this? I'll be very thankful for that.
It looks like your code is trying to set the value of response_body, which does not seem like what you want to do. The error is telling you that there is no setter for the attribute...
Related
I tried to deploy a non public project but sometimes when tried to use
report pages (based on prawn) I have this problem:
NoMethodError (undefined method `get_yaml' for #<String:0x7fdecffd3738>):
The piece of code is:
report_content = report.draw(report_content.get_yaml)
Someone know: where are get_yaml come from?
Thanks.
The method #get_yaml is not a part of of the standard Ruby library, although #to_yaml is defined if the yaml library has been loaded. #get_yaml, if it exists, is defined by the application or by some library that the application is loading.
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.
I am using rails 3.2.16 and ruby 1.9.3
I get this error from the localhost browser after rails s.
undefined method `to_date' for nil:NilClass
like this
NoMethodError in Products#new
Showing /Users/main/railscasts-episodes/episode-350/store-
after/app/views/products/_form.html.erb where line #27 raised:
undefined method `to_date' for nil:NilClass
in irb> mode it works only when I
require 'date'
Now my question is about my rails project. In which file in my project I should add
require 'date'
I added it into my model it did not work. Or, maybe I need to install any specific gem? to make this work
The problem you have isn't an issue with to_date, it's a problem with the object you're trying to perform the method on
Your issue will either be:
You have not declared the variable / object
Your variable / object is not populated with any data
I'd highly recommend posting the controller action you're using to invoke the to_date method. Obviously, there may be an issue with the way you're calling it, but the immediate issue is you're trying to deal with an unpopulated variable
I'm working with Spree 2.1 and trying to add new payment gateway, but this error is more generic so Spree itself is not-so-important here.
I have encountered that error (undefined method 'association_class' for nil:NilClass) after adding some module to Spree::PaymentMethod (source) class:
spree/payment_method_decorator.rb
Spree::PaymentMethod.class_eval do
include Spree::Core::CalculatedAdjustments
end
(Spree::Core::CalculatedAdjustments source)
(Spree::Gateway source)
Unfortunately, now Spree::PaymentMethod (source) breaks a little, i.e:
n = Spree::PaymentMethod.first
=> #<Spree::Gateway::Bogus id: 1, (...)>
n.save
=> undefined method 'association_class' for nil:NilClass
n.calculator
=> undefined method 'association_class' for nil:NilClass
Does anyone know why this happens and how to fix it?
In fact I already have an answer (after few hours of struggle), but maybe someone will give a better one with proper explanation. Maybe the answer is quite obvious, but it wasn't for me and I couldn't find anything related on SO so hopefully someone else with similar level of RoR knowledge won't have to spend another few hours on that.
So the answer was:
As it is visible in above links, Spree::Gateway is inheriting from Spree::PaymentMethod and my custom payment method was inheriting from Spree::Gateway class - something like:
module Spree
class Gateway::CustomMethod < Gateway
end
end
All I had to do was to include Spree::Core::CalculatedAdjustments in Spree::Gateway:
Spree::Gateway.class_eval do
include Spree::Core::CalculatedAdjustments
end
and it is working since then.
I am using the Cucumber unit test tool, and am trying to retrieve the value of a textarea, however I can't get it to work.
This is my code...
page.find(:xpath, "//div[#id='process']/table/tbody/tr/td/div/textarea").value
This is the error I'm getting...
Error: undefined method `value' for nil:NilClass (NoMethodError)
This URL listed below confirms that value is the correct method to retrieve the value:
http://www.w3schools.com/jsref/dom_obj_textarea.asp
Could someone please help me fix this problem.
The nil error indicates that you're not getting the textarea -- find is returning nil. Try a simpler xpath query, or referencing the textarea by name or id.