Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Activeadmin - custom association select box

In my Rails application, I have the following model:

class Idea < ActiveRecord::Base
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :ideas
end

I am creating ActiveAdmin CRUD for my Idea model with the custom form that looks something like that looks something like that:

form do |f|
  f.inputs do
    f.input :member
    f.input :description
  end
end

The requirement is to have the custom text for a content of the member association, i.e "#{last_name}, #{first_name}". Is it possible to customize my member select box to achieve it?

Any help will be appreciated.

like image 328
alexs333 Avatar asked Mar 19 '13 04:03

alexs333


1 Answers

Yes, that is possible. I assume you want to use a DropDown list box for members to select a user from User model.

form do |f|   f.inputs do     f.input :user_id, :label => 'Member', :as => :select, :collection => User.all.map{|u| ["#{u.last_name}, #{u.first_name}", u.id]}     f.input :description   end end 
like image 108
HungryCoder Avatar answered Sep 21 '22 14:09

HungryCoder