ActiveAdmin.register Employee do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
permit_params :email,:password,:password_confirmation,profile_attributes:[:name,:date_of_birth,:contact,:current_address,:permanent_address]
# or
#
# permit_params do
# permitted = [:permitted, :attributes]
# permitted << :other if params[:action] == 'create' && current_user.admin?
# permitted
# end
index do
column :email
column 'Name' do |f|
f.profile.name if !f.profile.nil?
end
column 'Birthday' do |f|
f.profile.date_of_birth if !f.profile.nil?
end
column 'Contact' do |f|
f.profile.contact if !f.profile.nil?
end
column 'Current address' do |f|
f.profile.current_address if !f.profile.nil?
end
column 'Permanent Address' do |f|
f.profile.permanent_address if !f.profile.nil?
end
actions
end
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs "Login Credentials" do
f.input :email
f.input :password
f.input :password_confirmation
end
f.actions
end
show do
attributes_table do
row :email
end
attributes_table_for employee.profile do
row :name
row :date_of_birth
row :contact
row :current_address
row :permanent_address
end
end
end
这是多次创建的
ActiveAdmin.register Profile do
permit_params :name, :date_of_birth, :contact, :employee_id, :current_address, :permanent_address
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs "Employee Profile" do
f.input :employee
f.input :name
f.input :date_of_birth, as: :datepicker
f.input :contact
f.input :current_address
f.input :permanent_address
end
f.actions
end
show do
attributes_table do
row :name
row :date_of_birth
row :contact
row :current_address
row :permanent_address
end
end
end
它们都是activeadmin资源。我如何将其限制为每个员工一个配置文件。