0

There is a constant called ENVIRONMENTS

validates :environment, inclusion: ENVIRONMENTS

with these associated constants and strings

ENVIRONMENT_INTERNAL="internal"
ENVIRONMENT_STAGING="staging"
ENVIRONMENT_PRODUCTION="production"
ENVIRONMENTS=[ENVIRONMENT_INTERNAL,ENVIRONMENT_STAGING,ENVIRONMENT_PRODUCTION]

I am trying to build a collection select which shows the strings related to the constants. How do I do it? This is how I have tried to do it

  =f.input :envrionment, as: :select, collection: [ENVIRONMENTS]
rico_mac
  • 888
  • 8
  • 22

2 Answers2

1

I had to access initialise the constant via the model;

  =f.select :environment, Deployment::ENVIRONMENTS, include_blank: 'Select'

this link proved useful here

Community
  • 1
  • 1
rico_mac
  • 888
  • 8
  • 22
0

f.select might come in handy here, as I have not used more of collection_select

<%= f.select 'server_id', ENVIRONMENTS, {:include_blank => "Select"} %>

value would be name as the selected entity

An ex:

<option value="internal">internal</option>
Nithin
  • 3,679
  • 3
  • 30
  • 55