4

So in my course on Coursera I'm required to build this rather simple aplication to obtain and display an array from an external api. I'm using the ruby on rails framework. (I'm using windows 10)

Controller -

class CoursesController < ApplicationController
  def index
    @search_term = params[:looking_for] || 'jhu'
    @courses = Coursera.for(@search_term)
  end
end

Model

class Coursera 
    include HTTParty
    default_options.update(verify: false) # Turn off SSL verification
    base_uri 'https://api.coursera.org/api/courses.v1'
    default_params fields: "photoUrl,description",q: "search"
    format :json

    def self.for term
        get("",query: {query: term}) ["elements"]
    end
end

The view is irrelevant as this works fine. But in my other app , I get this error -

Errno::ECONNREFUSED: Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80)

This is the other app which I'm having the problem with -

Controller -

class RecipesController < ApplicationController
  def index
    @search_term = params[:search] || 'chocolate'
    @recipes = Recipe.for @search_term

  end

end

Model -

class Recipe
    include HTTParty
    default_options.update(verify: false) # Turn off SSL verification
    key_value = ENV['FOOD2FORK_KEY']
    hostport = ENV['FOOD2FORK_SERVER_AND_PORT'] || 'food2fork.com'
    base_uri = "https://doesntmatter.com/api"  #website mentioned here         
                               #doesn't matter , I get the error nonetheless
    default_params key: ENV['FOOD2FORK_KEY'] ,q: "search"
    format :json
    def self.for term
        get("/search",query: {query: term}) ["recipes"]
    end

end

I've tried disabling all possible firewalls , unblocked all ports with TCP in windows firewall , but I still get the same error. Any ideas how to fix this ? Because I don't think its a problem in my code yet...

Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
Mihir Deshpande
  • 105
  • 2
  • 2
  • 5
  • Did you already try to send the request from your machine with the browser or wget? – hewo Jan 05 '18 at 11:13

1 Answers1

6

You have an excess symbol in your code:

class Recipe
  # some code here
  base_uri = "https://doesntmatter.com/api" 
           ^ # the equal symbol is redundant.
             # remove it and all will works as expected
  # ....
end
tennabey
  • 295
  • 3
  • 16
Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
  • It’s not _redundant_, it literally _breaks everything_ :) – Aleksei Matiushkin Jan 05 '18 at 12:11
  • oh my god I have never been so embarassed in my life , thank you It's just I've had a loooot of problems with my net connection and firewall problems before that as soon as I saw something like connection can't be stablished I just instantly assumed it's because of some blocked ports or something :p – Mihir Deshpande Jan 05 '18 at 12:16
  • Just quick shout out to Mihir Deshpande and Зелёный, the initial problem outlined here and the answer just saved me hours of derp ID10T grinding on a why-no-rake-working mess. Thanks! – HAL-9000 Feb 21 '19 at 22:56