Hi, I am working on a Rails 3.2.9 application that uses devise and ActiveAdmin. I have models like users and companies. I want the administrator to choose one manager from the list of registered users for a particular company.
My user table has the following fields: id, username, email, company_id, password, etc.
My companyβs table contains: id, company_name, manager_id (this is nothing more than a user ID), created_at, etc.
After the administrator has selected a manager for the company, I want his name (username from the user table) to appear on the index page for the company, but now only the manager_id is displayed on the index page. (When editing, the drop-down list for manager selection shows a list of usernames)
Pls tell me how to use query / join to accomplish this
Here is my company.rb file for admin
ActiveAdmin.register Company do index do column "Company", :name column :address column "No. of Subscriptions", :no_of_licenses column "Manager", :manager_id default_actions end filter :name form do |f| f.inputs "Company Details" do f.input :name f.input :address f.input :no_of_licenses, :label => 'No of Subscriptions' f.input :manager_id, :as => :select, :collection => User.joins('LEFT OUTER JOIN companies ON users.company_id = companies.id').map{|u| [u.username, u.id]} end f.buttons end end
source share