LoginSignup
2
1

More than 1 year has passed since last update.

【jp_prefecture】rails_adminで都道府県一覧セレクトボックスを表示する

Posted at

RailsAdminでjp_prefecture gemを使用して、都道府県一覧セレクトボックスを作成するのに少しハマったのでメモ。
下記のようにEnumとして定義してあげれば無事動作できました。

class City < ApplicationRecord
  include JpPrefecture
  jp_prefecture :prefecture_code

  rails_admin do
    create do
      field :prefecture_code, :enum do
        enum JpPrefecture::Prefecture.all.collect { |p| [p.name, p.code] }
      end
      field :name
      field :description
    end

    edit do
      field :prefecture_code, :enum do
        enum JpPrefecture::Prefecture.all.collect { |p| [p.name, p.code] }
      end
      field :name
      field :description
    end
  end
end

2
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
2
1