m247/tickets — comment on commit 2fd4c883eb403d15e72b1ea142743e2a2a1cce7f
File: app/models/issue.rb line 5
By bigos:

Hi,

I was thinking about something like this that would work in many models:

#generating options for select from array
arr=%w(bronze silver gold platinum)
z=0
arr.map {|m| p [m,z+=1]}

On 07/03/12 22:37, Geoff Garside wrote:
> For things like that I'd leave the PRIORITIES and STATUSES as arrays of strings. The priority and status fields in the database would then be one of these string values. So `validates_inclusion_of :priority, :in => PRIORITIES`.
>
> For the forms I'd then use
>
> = f.select :priority, Issue::PRIORITIES.map { |p| [p, p] }
>
> as a simple case.
>
> You can quite pleasantly use the I18n translation stuff to make it nicer, such as
>
> = f.select :priority, Issue::PRIORITIES.map { |p| [t("issue.priorities.#{p}"), p] }
>
> which will then look up the `issue.priorities.bronze`, `issue.priorities.silver`, `issue.priorities.gold` or `issue.priorities.platinum` translations accordingly. You'd then also use these localisation keys when showing the priority levels in the templates. You'd probably use a helper for this.
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/m247/tickets/commit/2fd4c883eb403d15e72b1ea142743e2a2a1cce7f#commitcomment-1056012
>