views:

27

answers:

1

i have a some values ,that i use in my model as constants.

class Animal < ActiveRecord::Base    
 LEGS = {:vierbeiner => 4, :zweibeiner => 2 }
end

in the form (formtastic) for the collection i use:

<%= f.input :legs, :as => :select, :collection => Animal::LEGS =>

but how do i format the show view so instead showing me the number , the key of the hash?

in show view i have:

<p>
  <strong>Legs:</strong>
  <%=h @animal.legs %>
</p> 
+1  A: 
Animal::LEGS.select{ |k,v| v == @animal.legs }.first.first

Though better make it a helper.

Jakub Hampl