'Ruby on Rails API: Call an API model method from another app

I have an API with the following QrCode model:

class QrCode < ApplicationRecord
    def self.get_by_link(link)
        return QrCode.all.find_by(link: link)
    end
end

QrCode has a link attribute. So, I connect the API with an app using ActiveResource. Here´s the QrCode model in the app:

class QrCode < ActiveResource::Base
    self.site = "http://localhost:4001/"
end 

So what I want is to simply call from any controller in the app, that get_by_link method like this:

class RegularController < ApplicationController
   before_filter :find_student

   def some_method
       qr =  QrCode.get_by_link("www.google.com")
   end 
end

And get a qr code based in the link I sent as parameter. For some reason that I don't know, I'm not able to call this method. It throws me an undefined method `get_by_link' for QrCode:Class.

NOTE: It´s my first time trying to use an API like this so, I know I'm making mistakes (I mean, it doesn't work), but I don't know where.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source