LoginSignup
1
1

More than 5 years have passed since last update.

ActiveAdminのtable_forに渡したcollectionが勝手にdecorateされるようにする

Last updated at Posted at 2015-02-23

シチュエーション

showでhas_many関係にある子要素のテーブル表示する時なんかに。

実装

module TableDecoration
  def build(obj, *attrs)
    ActiveDecorator::Decorator.instance.decorate(obj)
    super(obj, *attrs)
  end
end

module ActiveAdmin
  module Views
    class TableFor < Arbre::HTML::Table
      prepend TableDecoration
    end
  end
end

余談

もともとはalias_method_chainを使った実装を試していたのですが、メソッド名が変わる影響か、TableFor#build内で呼ぶsuperが機能しておらず、prependを使った方法に切り替えています。エラーにはならず、ただtrの中にtdがrenderされなかっただけで、詳細な理由は調査しきれていないです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1