activeadmin resource(employee)创建多个配置文件(另一个资源),而不是has_one关系

时间:2016-10-19 12:41:26

标签: ruby-on-rails devise associations activeadmin

Employee.rb(活动管理资源,has_one:个人资料)

    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

profile.rb(Activeadmin资源,belongs_to:employee)

这是多次创建的

  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资源。我如何将其限制为每个员工一个配置文件。

0 个答案:

没有答案