Based on feedback, I am revising this question. How do i convert an integer array to a set of values displayed on the view page using the Constants (defined in the model). I can do it on my form page but have not figured it out for the Index.
On an Index Page (if dbase has grades: [0, 1, 2], the page should display as A+, A, B)
something like what is done for days of the week (e.g. http://hightechsorcery.com/2010/02/16/ruby-arrays-and-hashes-and-days-of-the-week/
....
<h4 class="h3"><%= @gradestemp %>
CONTROLLER Labels Controller
def index
@labels = current_user.labels
grad = []
@gradestemp = Contact::GRADES.each_with_index { |x, i| grad << [x, i] }
render
end
MODEL NB: GRADES is a constant - I am trying to also use in Labels class Label < ActiveRecord::Base NB: this is in the CONTACT model
GRADES = [["A+",0 ], ["A",1], ["B", 2], [ "C",3], [ "D",4], [ "-",5]]
Am i able to access the Contact GRADES while in the Labels controller?
i have found this SO - which is similar to what i am trying to do: Ruby: How to store and display a day of the week?
Based suggestion below, this did the trick:
<h4 class="h3"><%= print_campaign.grades.compact.map{|idx| Contact::GRADES[idx][0]}.join(' ') %>
{}button, to format it. I tried editing it for format, but your post was too jumbled with details for me to handle