刚刚学习 rails,又写了个rails admin 的 china city 插件
依赖 @saberma 的 china_city gem
先按照china_city gem 的安装流程,之后添加 gem 到 Gemfile:
gem 'rails_admin_china_city_field', github: 'TangMonk/rails_admin_china_city_field'
class Businessman
embeds_one :address, class_name: "Address", as: :addressable # or has_one is ok.
rails_admin do
field :address, :china_city
end
end
class Address
include Mongoid::Document
field :province, type: String
field :city, type: String
field :district, type: String
embedded_in :addressable, polymorphic: true # or belongs_to is ok.
end
设置默认的字段名称:
rails_admin do
field :address, :china_city do
province_field :my_province
city_field :my_city
district_field :district
end
end