Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin forms (new/edit) belongs_to association?

I use Active Admin gem for Ruby on Rails. I have modules Team and Coach, which have a has_many and belongs_to relationship.

class Team < ActiveRecord::Base
  belongs_to :coach
end

class Coach < ActiveRecord::Base
  has_many :teams
end

I figured out how to display first name and last name on index and show page (i did it like that:)

  index do
    column :name
    column "Coach" do |team|
      team.coach.firstname + " " + team.coach.lastname
    end  
     default_actions
  end

What i want is how to display first name and last name of coach in Team form (new and edit page) in dropdown menu? Please help me with this.

like image 961
Luka Avatar asked Apr 14 '12 11:04

Luka


1 Answers

Can you try this

f.input :coach_name, :as => :select, :collection => Coach.all.map {|u| [u.firstname, u.id]}, :include_blank => false
like image 183
Amal Kumar S Avatar answered Sep 19 '22 00:09

Amal Kumar S