Henrik Zakaryan
Henrik Zakaryan

Reputation: 29

undefined local variable or method `api' for main:Object (NameError)

Hi guys i'm new on RoR and have question, i'm getting this error on my Terminal when i'm trying to run > ruby api_controller.rb

undefined local variable or method `api' for main:Object (NameError)

Here my code:

 require 'rubygems'  
 require 'httparty'

 url = https://api.coinmarketcap.com/v2/listings/ 
 response = HTTParty.get(url) 
 response.parsed_response


 class Coinmarketcap
    include HTTParty
    base_uri 'api.coinmarketcap.com'

   def listings
     self.class.get('/v2/listings/')
   end 
 end


 coinmarketcap = Coinmarketcap.new 
 puts coinmarketcap.listings

 coinmarketcap.listings.each do |post|   
  #puts "Id: #{post['id']        
 end

Upvotes: 0

Views: 1678

Answers (1)

LolWalid
LolWalid

Reputation: 545

Missing quote arround the url

Should be:

url = 'https://api.coinmarketcap.com/v2/listings'

I copy/paste your code and it's working with above modification

Upvotes: 1

Related Questions