Active Admin访问两个模型

时间:2013-05-22 15:51:46

标签: ruby-on-rails activeadmin

我想使用Active Admin从配置文件访问数据。

个人资料有这个型号:

class Profile < ActiveRecord::Base
  attr_accessible :address, :name, :phone
  belongs_to :user

end

Print(orders)有这个型号:

class Print < ActiveRecord::Base
  ....

  belongs_to :user
  has_one :profile
...
end

两个模型都有User_id列,来自User模型。 和Print(Orders)print.rb写成:

ActiveAdmin.register Print, :as => "Order" do

     index do
      column "Document", :document_file_name do |print|
         link_to print.document_file_name, print.document.url
      end
      column "Size", :document_file_size do |print|
            number_to_human_size(print.document_file_size)
      end
      column "Print Status", :is_printing
      column "Deliver Status", :is_delivered
      column "Comments", :comment
      default_actions
     end

     show do
       panel "Invoice" do
        table_for(order.user.profile) do
          column "name" do |profile|
           profile.name
          end
        end
       end
     end

end

如何从配置文件中获取数据,例如:来自Active Admin的地址?

编辑:

我正在分享我的解决方案,因为有人要求它:

sidebar "Customer Details", :only => :show do
   attributes_table_for customer.profile do
      row("Email") { customer.email }
      row("Name") { auto_link customer.profile.name }
      row("Address") { auto_link customer.profile.address }
      row("Phone") { auto_link customer.profile.phone }
    end
 end 

1 个答案:

答案 0 :(得分:1)

试试这个

column :address do |order|
 order.user.address
end