Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created July 22, 2016 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/328766c74b20733faafac476f3a7a5fc to your computer and use it in GitHub Desktop.
Save anonymous/328766c74b20733faafac476f3a7a5fc to your computer and use it in GitHub Desktop.
# Line 4 of this class:
class CoursesController < ApplicationController
def index
@search_term = 'jhu'
@courses = Coursera.for(@search_term)
end
end
# Causes: undefined method `for' for Coursera:Module
# However it's defined in app/models/coursera.rb shown below:
class Coursera
include HTTParty
base_uri 'https://api.coursera.org/api/catalog.v1/courses'
default_params fields: "smallIcon,shortDescription", q: "search"
format :json
def self.for term
get("", query: { query: term })["elements"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment