Constants in Model and View with select option and show view

Posted by caplod on Stack Overflow See other posts from Stack Overflow or by caplod
Published on 2010-05-17T16:07:35Z Indexed on 2010/05/17 16:10 UTC
Read the original article Hit count: 198

Filed under:

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> 

© Stack Overflow or respective owner

Related posts about ruby-on-rails