LoginSignup
3
4

More than 5 years have passed since last update.

ActiveAdmin の filter で、あるモデルに associate しているモデルを使う

Last updated at Posted at 2015-10-20
schema.rb
ActiveRecord::Schema.define(:version => 20150000123456) do
  create_table "users", :force => true do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  create_table "products", :force => true do |t|
    t.string   "name"
    t.integer  "user_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
end

というモデルの構成だった場合、

app/admin/products.rb
ActiveAdmin.register Product do
  filter :user_name, as: :string
end

とすることで User.name で検索できるようになる。

3
4
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
3
4