【问题标题】:Active Admin accessing two modelsActive Admin 访问两个模型
【发布时间】:2014-03-20 16:08:47
【问题描述】:

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

个人资料有这个型号:

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

end

打印(订单)有这个模型:

class Print < ActiveRecord::Base
  ....

  belongs_to :user
  has_one :profile
...
end

两个模型都包含来自 User 模型的 user_id 列。 而打印(订单)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 

【问题讨论】:

  • 你指的是哪个版本的 ruby​​ on rails?

标签: ruby-on-rails activeadmin


【解决方案1】:

试试这个

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

【讨论】:

  • tables_for 怎么样?我试过 order.user.profile 但它不起作用,给出一个错误:未定义的方法 `each' for #<0x007f8ab8106130>
猜你喜欢
  • 2014-04-18
  • 1970-01-01
  • 2012-11-30
  • 2022-01-27
  • 1970-01-01
  • 1970-01-01
  • 2012-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多