Ruby on rails 什么是activerecord.values.columnattribute
我得到了一个事件助手模块,有人在rails应用程序中编写了该模块。我正在开发一个表单,可以让某人创建一个新事件 这是表格的一部分Ruby on rails 什么是activerecord.values.columnattribute,ruby-on-rails,ruby,activerecord,Ruby On Rails,Ruby,Activerecord,我得到了一个事件助手模块,有人在rails应用程序中编写了该模块。我正在开发一个表单,可以让某人创建一个新事件 这是表格的一部分 =form.input :sponsorship_type, collection: get_event_labels(:event_types), as: :select_other =form.input :society_name 过去是这样 =form.input :event_type, collection: get_event_labels
=form.input :sponsorship_type, collection: get_event_labels(:event_types), as: :select_other
=form.input :society_name
过去是这样
=form.input :event_type, collection: get_event_labels(:sponsorship_types), as: :select_other
=form.input :society_name
根据客户机请求,我必须从events表中删除event_type列,并添加此列
t.string "sponsorship_type"
旧的模式有以下特点
t.string "event_type"
这是模块
module EventsHelper
LABEL_MAP = {
institutions: [::INSTITUTIONS, 'activerecord.values.institutions.name'],
event_types: [::EVENT_TYPES, 'activerecord.values.event_types'],
industries: [::INDUSTRIES, 'activerecord.values.industries'],
referrers: [::REFERRERS, 'activerecord.values.referrers'],
regions: [::REGIONS, 'activerecord.values.regions'],
cities: [::CITIES, 'activerecord.values.cities']
}.freeze
def get_event_labels(type)
if Geokit::Geocoders::IpGeocoder.geocode(remote_ip).country_code == 'TW' and type == :event_types
return {
'活動/班' => 'Activities/Classes',
'食品和飲料' => 'Food&Beverage',
'優惠券' => 'Coupons',
'現金' => 'Cash',
'器材' => 'Equipment',
'獎品' => 'Prizes'
}
end
Hash[
LABEL_MAP[type][0].map do |constant|
[I18n.t("#{LABEL_MAP[type][1]}.#{constant}"),
constant]
end
]
end
def remote_ip
request.remote_ip
end
end
这是什么?[::事件类型,'activerecord.values.EVENT类型']
我试着把所有的活动类型都改成赞助类型。然后我得到一个
': uninitialized constant SPONSORSHIP_TYPES (NameError)
这可能是因为activerecord.values.promotion\u类型
没有值。如何访问它并输入值
这是什么
::EVENT_TYPES
我的最终目标是返回散列
return {
'活動/班' => 'Activities/Classes',
'食品和飲料' => 'Food&Beverage',
'優惠券' => 'Coupons',
'現金' => 'Cash',
'器材' => 'Equipment',
'獎品' => 'Prizes'
}
作为表单上用户的选择选项 事件类型是一个常量。它必须在该应用程序中的某个位置定义,可能在控制器中或
config
文件夹中的某个位置。找到它并以相同的方式定义您的赞助类型
activerecord.values.event\u类型
看起来像一个本地化键。查看config/locales/…
中的本地化文件,查找具有此结构的yaml哈希。以相同的方式添加新节点u类型