Question

I got an events helper module that somebody coded in a rails application. I am working on a form that can allow someone to create a new event.

here is a part of the form

  =form.input :sponsorship_type, collection: get_event_labels(:event_types), as: :select_other
  =form.input :society_name

it used to be

  =form.input :event_type, collection: get_event_labels(:sponsorship_types), as: :select_other
  =form.input :society_name

per the client request I had to drop the event_type column from the events table and added this instead

t.string   "sponsorship_type"

the old schema has this

 t.string   "event_type"

this is the module

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

what is this? [::EVENT_TYPES, 'activerecord.values.event_types']

i tried just changing all the event_types to sponsorship_type. and then I am getting a

': uninitialized constant SPONSORSHIP_TYPES (NameError)

Its probably because activerecord.values.sponsorship_types have no values. How do I access it and put in values?

what is this?

::EVENT_TYPES

my end goal is to return the hash

  return {
    '活動/班' => 'Activities/Classes',
    '食品和飲料' => 'Food&Beverage',
    '優惠券' => 'Coupons',
    '現金' => 'Cash',
    '器材' => 'Equipment',
    '獎品' => 'Prizes'
  }

as selection option for the user on the form.

Was it helpful?

Solution

EVENT_TYPES is a constant. It must be defined somewhere in that application, perhaps in the controller or somewhere in the config folder. Find it and define your SPONSORSHIP_TYPES in the same way.

activerecord.values.event_types looks like a localization key. Look into your localization files in config/locales/... for some yaml hash with this structure. Add a new node sponsorship_types in the same way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top