简体   繁体   中英

Include Gem Not Working

I'm getting a weird error when I'm trying to include a gem within my controller, below is the code i'm using in the controller and the error I get is:

> undefined method `include' for <CatalogController:0x00000002427b90>

The code returning this error is as follows:

require 'httparty'
require 'json'

class CatalogController < ApplicationController

    # GET /feeds
    # GET /feeds.json
    def index
      # GRAB THE URL
      include HTTParty
      base_uri 'https://www.parsehub.com/api/v2/runs'

      # PARSE THE RESPONSE

      def art
        response = self.class.get("/tnZ4F47Do9a7QeDnI6_8EKea/data?&format=json")
        @elements = response.parsed_response["image"]
        @parsed = @elements.collect { |e| e['url'] }
      end


    end

end

Not too sure why this error is returning?

You don't need include. In fact, you shouldn't even need that require. I assume this is a rails app. If you have the httparty gem installed via your Gemfile , you can simply make calls with httparty throughout your application.

Also move that art method outside of your index method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM