require 'administrate/field/belongs_to' require 'rails' module Administrate module Field class BelongsToSearch < Administrate::Field::BelongsTo class Engine < ::Rails::Engine initializer 'administrate-field-belongs_to_search.add_assets' do |app| app.config.assets.precompile << 'belongs_to_search.js' if app.config.respond_to? :assets Administrate::Engine.add_javascript 'belongs_to_search.js' if defined?(Administrate::Engine) end end def associated_class super end def belong_to_scope_package(current_user, model) # create a room need package reference # model is Package model_variable = model.to_s.underscore.pluralize # so we scope the current user packages # sed(...) t.ly/56cI scoped_model = current_user.send(model_variable).pluck(:id) # array = [] # puts "candidate_resources => #{candidate_resources}" # candidate_resources.each do |resource| # array << resource.send(primary_key) # end candidate_resources = Package.find(*scoped_model) [nil] + candidate_resources.map do |resource| [display_candidate_resource(resource), resource.send(primary_key)] end # array_key = array.keys # array_toto = array.pluck(:primary_key) # puts array_key # scoped_model.filter {|item| array.include?(item)} end # def associated_resource_options # [nil] + candidate_resources.map do |resource| # [display_candidate_resource(resource), resource.send(primary_key)] # end # end def associated_resource_options_short array = [] candidate_resources.each do |resource| array << resource.send(primary_key) end array end end end end