I'm having difficulties to add a custom class to my app.
It's a class that spiders a website and returns the results.
What i've found out is that I need to put it in the lib folder, I already pointed the autoload paths to the lib folder.. This is where I put it:
# /lib/booking_spider.rb
class BookingSpider
def cities( city )
return @cities
end
end
This is how I call it in my controller:
p BookingSpider.cities( params[:search][:city] )
This error keeps popping up:
undefined method `cities' for BookingSpider:Class
Can someone tell me what I'm missing here?
Thanks!
You are trying to use the method as a class method, but it is defined as an instance method. Change to this:
class BookingSpider
def self.cities(city)
return @cities
end
end
Here is some reading on the differences between class and instance methods: method types in Ruby
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With