Rails类方法未定义

时间:2019-01-03 23:10:56

标签: ruby-on-rails ruby model controller class-method

我有一个控制器,它从模型中调用类方法。但是,我得到了undefined method 'where' for Jira:Class

controller:

module Api
  module V1
    class JiraController < ApplicationController

      def index
        jira = Jira.where()
        jira_stat = JiraStat.new(jira)
        render json: [
          {
            t('jira.api.status') => jira_stat.status,
            t('jira.api.number_of_jiras') => jira_stat.jira_total
          }
        ]
      end
    end
  end
end


model:
# frozen_string_literal: true

require 'active_model'

class Jira
  include ActiveModel::Model
  include JiraKit

  attr_accessor :status, :jira

  def self.where(status_name = 'all')
   if status_name == 'all'
     jiras = JiraKit.where.jira_issues(status: ['open', 'submitted', 'in 
 progress', 'in review', 'closed'])
    elsif
     jiras = JiraKit.where.jira_issues(status: [status_name])
   end
   new(@status = status_name, @jira = jiras)
 end
end

我认为我使用了self关键字。但是我不知道为什么我无法访问该方法。如果创建Jira模型的实例,则可以访问该方法。

0 个答案:

没有答案