2016-01-28 67 views
0

我使用活动管理与ActiveRecord范围。不过,我在添加范围时遇到了问题。活动管理范围不起作用1.0.0.pre2

运行红宝石2.2.1p85(2015年2月26日修订49769)x86_64的Linux的]和 Rails的4.2.5.1

#app/model/accounts.rb 
    class Account < ActiveRecord::Base 

    searchkick 


    belongs_to :program 
    belongs_to :insurance 
    has_many :notes 
    scope :program_name, -> (program) {where(program_name: adult) } 

    validates :first_name, :last_name, :address, :phone, presence: true 
    validates :phone, format: { with: /\A\d{3} \d{3}-\d{4}\z/, 
    message: "must be in the format 123 456-7890" } 
    end 

我希望能够给我们在这个应用程序/管理/账户.rb

#app/admin/account.rb 

      ActiveAdmin.register Account do 
      menu :priority => 2 
      permit_params :first_name, :last_name, :return_client, :program_id, :insurance_id, :address, :phone 



      index do 
       column :first_name 
       column :last_name 
       column :address 
       column :phone 
       column :created_at 
       column :return_client 
       column :program 
       column :insurance 
       actions 
      end 
      scope :all, :default => true 

      scope :adult, default: true do |accounts| 
       accounts.program_name('adult') 
      end 
      end 

我厌倦了它使用它和无块。我希望该范围内的“程序”总数作为最终结果。

+0

尽管我从来没有使用过它,但我已经看过它的文档,并且似乎模型完全由框架管理。和“范围”一词可以自己冲突 “范围”,一个过滤器屏幕。我总是避免使用框架或插件,如果我可以自己做 –

回答

0

您不能有两个默认范围,并且不需要scope :all,因此请将其删除。

你有这样的范围也很正常

scope :program_name, -> (program) {where(program_name: adult) } 

和你说

我希望能够给我们在这个应用程序/管理/ account.rb

但你并没有真正使用它。你是不是尝试使用

scope :adult, default: true do |accounts| 
    accounts.program_name('adult') 
end 

所以只是将它加入

scope :program_name 

但你的问题似乎装有别的东西,你现在要做的

我希望该范围内“程序”的总数作为最终结果。

而在这个意义上,我认为你可能会误解scopes的实际用途。