在Rails上没有方法错误的高级搜索红宝石

时间:2019-04-04 20:22:46

标签: ruby-on-rails devise

我有一个高级搜索页面,其中带有用于合同的单独搜索控制器。目前,我的显示页面(搜索结果)出现错误,因为我最近更改了search.rb中的方法,因此它仅显示与current_user相关的记录。

我正在使用Devise。

下面是我的search.rb

class Search < ActiveRecord::Base


  def self.user_search_contracts(user)
      user ||= User.new
      contracts = Contract.where(user_id: user.id)

    contracts = contracts.joins(:tenant).where(["tenants.first_name LIKE ? OR tenants.last_name LIKE ?", "%#{keywords}%", "%#{keywords}%"]) if keywords.present?
    contracts = contracts.where(["balance >= ?", min_balance]) if min_balance.present?
    contracts = contracts.where(["balance <= ?", max_balance]) if max_balance.present?
    contracts = contracts.where(["unpaid_rent LIKE ?", unpaid_rent]) if unpaid_rent.present?

    return contracts
  end

end

显示搜索页面

.wrapper_with_padding
  #houses.clearfix
    - unless @search.user_search_contracts.blank?
      - @search.user_search_contracts.each do |contract|
        %a{ href: (url_for [contract])}
          .house
            %p.end_of_contract= contract.end_of_contract
            %p.balance= number_to_currency(contract.balance, :unit => "£", negative_format: "(%u%n)")
            -if contract.tenant.present?
              %p.tenant_id= contract.tenant.full_name
            -else
              %p No Tenant Assigned
            -if contract.house.present?
              %p.house_id= contract.house.full_house_name
            -else
              %p No Property Assigned

错误:#

的未定义方法`user_search_contracts'

0 个答案:

没有答案