2012-02-01 27 views
1

我有這個模型屬性:主動聯繫使屬性的集合模型

class CreateRoles < ActiveRecord::Migration 
    # create role model with relation to users and projects 
    def change 
    create_table :roles do |t| 
     t.references :user 
     t.references :project 
     t.boolean :senior_author , :default => 0 
     t.boolean :first_author  , :default => 0 
     t.boolean :author   , :default => 0 
     t.boolean :bio_informatician, :default => 0 
    end 
    end 
end 

我的形式是:

form do |f| 
    f.inputs "Details" do # Project's fields 
    f.input :title 
    f.input :code 
    end 

    f.has_many :roles do |app_f| 
    app_f.inputs do 
     if !app_f.object.nil? 
     app_f.input :_destroy, :as => :boolean, :label => "Effacer" 
     end 

     app_f.input :user, :include_blank => false, :label_method => :to_label 
     #app_f.input :senior_author 
     #app_f.input :first_author 
     #app_f.input :author 
     #app_f.input :bio_informatician 
    end 
    end 
    f.buttons 
end 

我怎樣才能讓一個集合()或單選按鈕最後四個app_f.input?

回答

5

您可以使用收集屬性

f.input :user, :collection => User.all.map{|u| [u.name, u.id]} 

我不知道這是否會幫助你,但我覺得是非常陌生的formtastic不與記錄的選擇。

+0

這種類型的集合中的地圖不適合我... activeadmin總是顯示我的u.name,而不是像我設置的u.cod ...我的集合:User.all.map {| u | [u.cod,u.id]} – squiter 2014-03-28 12:46:46

+0

@BrunnoDosSantos你的activeadmin版本是什麼? – Duke 2014-03-28 14:23:18

+0

activeadmin(1.0.0.pre) – squiter 2014-03-28 18:52:11