Skip to content

Instantly share code, notes, and snippets.

@mbhnyc
Created July 7, 2013 17:43
Show Gist options
  • Save mbhnyc/5944282 to your computer and use it in GitHub Desktop.
Save mbhnyc/5944282 to your computer and use it in GitHub Desktop.
1 Way to store constants on the model and use in a view
# In model:
STATUS_CHOICES = {
default: "Ask me",
single: "Single",
relationship: "Relationship",
married: "Married",
divorced: "Divorced",
complicated: "Takes some explaining",
open: "Open Relationship",
separated: "Separated"
}
# In edit view (simplified):
= simple_form_for resource, as: resource_name, url: registration_path(resource_name), html: {multipart: true, method: :put, class: 'inline' } do |f|
.inputs
= f.simple_fields_for :datingprofile do |dp|
= dp.input :relationship_status, required: true, label: "Status: ", collection: Datingprofile::STATUS_CHOICES.invert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment