Hi I'm working on a Rails 3.2.9 app which uses devise and ActiveAdmin. I have models like users and company. I want admin to select one manager from list of registered users for a particular company.
My user's table has these fields : id,username, email, company_id, password etc
My company's table has : id, company_name, manager_id (this is nothing but id of user), created_at etc
After the admin has selected a manager for a company , i want his name(username from users table) to appear in the index page for company but now only manager_id is shown in index page. (On edit, the dropdown for selecting manager shows list of usernames)
Pls let me know how to use a query/joins statement to accomplish this
Here's my companies.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