mardi 17 novembre 2015

Capitalize the drop down (option) values

I am retrieving values from DB and binding it in haml. I am trying to capitalize the values in drop down option.

models.rb

class EnumValue < ActiveRecord::Base

  attr_accessible :enum_type, :name, :gdsn
  scope :countries, EnumValue.where(enum_type: "country").order(:name)
end

form.html.haml

.offset1.span2
        = f.association :country, :collection => EnumValue.countries,:include_blank => "Select Country",:label => "Country of Origin",:selected =>@records.country_id ? @records.country_id, :input_html => {:onchange =>"setGdsnName(this.value,'country')"}

I tried to call capitalize on EnumValue.countries.capitalize in haml, and I got the following error: undefined method capitalize for # ActiveRecord::Relation:0x123d0718>.

Can anyone tell me how to capitalize the values in drop down using active records?

Aucun commentaire:

Enregistrer un commentaire