Ruby on rails ActiveRecord finder方法,其中不筛选查询结果

Ruby on rails ActiveRecord finder方法,其中不筛选查询结果,ruby-on-rails,ruby-on-rails-4,scope,class-method,activerecord-relation,Ruby On Rails,Ruby On Rails 4,Scope,Class Method,Activerecord Relation,TL;DR:当我使用类方法在活动和非活动居民之间进行作用域时,为什么会收到所有居民的列表 我的应用程序使用。租户模型称为Account,它有许多管理居民的员工 class Account < ActiveRecord::Base before_create :set_subdomain has_one :admin, class_name: 'Employee', foreign_key: :account_id, dependent: :destroy, inver

TL;DR:当我使用类方法在活动和非活动居民之间进行作用域时,为什么会收到所有居民的列表

我的应用程序使用。租户模型称为Account,它有许多管理居民的员工

class Account < ActiveRecord::Base
  before_create :set_subdomain

  has_one  :admin, class_name: 'Employee', foreign_key: :account_id, 
    dependent: :destroy, inverse_of: :account

  has_many :employees, class_name: 'Employee', foreign_key: :account_id, 
    dependent: :destroy, inverse_of: :account

  has_many :residents
  has_many :invites
  has_many :daily_summaries
  has_one  :subscription
  .
  .
  .
end
我允许员工查看软删除的居民&提供活动/非活动居民的选项卡式索引视图

在我的常驻类中,我有以下基于活动/非活动状态的类方法

  class Resident < ActiveRecord::Base
    acts_as_tenant(:account)
    .
    .
    .
    def self.inactive_count(current_account)
      where({ account_id: current_account.id, is_active: false }).count
    end

    def self.default(current_account)
      where({ account_id: current_account.id, is_active: true })
    end

    def self.inactive(current_account)
      # where({ account_id: current_account.id, is_active: false })
      where("account_id = ? AND is_active = ?", current_account.id, false).first 
    end

    def archive
      update_attribute(:is_active, false)
    end
    .
    .
    .
  end
到目前为止,我的阅读需要解决:

包含服务器日志以显示SQL

视图模板

index.html.erb

  <li class="active">
    <a href="#" data-toggle="tab">
      Active Residents&nbsp;&nbsp;
      <span class="badge badge-purple">
        <%= @active_resident_count %>
      </span>
    </a>
   </li>
   <li>
     <a href="#" data-toggle="tab">
       Inactive Residents&nbsp;&nbsp;
       <span class="badge badge-dark">
         <%= @inactive_resident_count %>
       </span>
     </a>
   </li>
_active_residents.html.erb

<% if @active_residents.any? %>
  <tbody>
    <% @active_residents.reverse_each do |resident| %>
      .
      .
      .
    <% end %>
  </tbody>
<% end %>
<% unless @inactive_residents.nil? %> 
  <% @inactive_residents.reverse_each do |resident| %>
    .
    .
    .
  <% end %>
<% end %>
_非活动_residents.html.erb

<% if @active_residents.any? %>
  <tbody>
    <% @active_residents.reverse_each do |resident| %>
      .
      .
      .
    <% end %>
  </tbody>
<% end %>
<% unless @inactive_residents.nil? %> 
  <% @inactive_residents.reverse_each do |resident| %>
    .
    .
    .
  <% end %>
<% end %>
评论后更新

我的日志在下面,当我在浏览器中选择“非活动”选项卡时,日志中没有任何更改。在开发工具中,我也看不到js控制台的任何输出,除非我为详细输出设置了一个选项。我将包括这一形象也。

这对我有用

总结以上链接:

如果使用数据属性方法,则必须将href属性设置为要打开的选项卡的ID。在JS版本中,您必须具有类似$'myTab a[href=profile]'。选项卡'show'的内容,才能打开href值设置为profile的选项卡

我的例子

在我添加的两个部分文件中

在index.html.erb中,我将href值从改为my_tab_id

这对我有用

总结以上链接:

如果使用数据属性方法,则必须将href属性设置为要打开的选项卡的ID。在JS版本中,您必须具有类似$'myTab a[href=profile]'。选项卡'show'的内容,才能打开href值设置为profile的选项卡

我的例子

在我添加的两个部分文件中

在index.html.erb中,我将href值从改为my_tab_id


这可能是UI/jQuery问题。查看是否在每个选项卡下呈现正确的数据。因为计数看起来是正确的。

这可能是UI/jQuery问题。查看是否在每个选项卡下呈现正确的数据。因为计数看起来是正确的。

可能是UI/jQuery问题。查看是否在每个选项卡下呈现正确的数据。因为计数看起来是正确的。谢谢@emaillenin,你是正确的!如果你将你的评论复制/粘贴到答案中,我会接受,因为你给我指出了正确的方向。可能是UI/jQuery问题。查看是否在每个选项卡下呈现正确的数据。因为计数看起来是正确的。谢谢@emaillenin,你是正确的!如果你将你的评论复制/粘贴到一个答案中,我会接受,因为你为我指出了正确的方向。
<ul class="nav nav-tabs tabs-right">
  <li class="active">
    <a href="#my_tab1_id" data-toggle="tab">
      Active Residents&nbsp;&nbsp;
      <span class="badge badge-purple">
        <%= @active_resident_count %>
      </span>
    </a>
   </li>
   <li>
     <a href="#my_tab2_id" data-toggle="tab">
       Inactive Residents&nbsp;&nbsp;
       <span class="badge badge-dark">
         <%= @inactive_resident_count %>
       </span>
      </a>
    </li>
  </ul>