Slick23
Slick23

Reputation: 5897

Is there an easy way to humanize string in collection_select?

Given this:

  <%= f.collection_select :role_id, @role, :id, :name %>

Is there an easy way to humanize or titleize the :name, if it's stored as something like super_admin ? I tried humanize(:name) but that didn't seem to work.

Upvotes: 1

Views: 757

Answers (1)

Shaunak
Shaunak

Reputation: 18018

A better way would be to add a method in the model 'role' which returns human name something like

class Role< ActiveRecord::Base

    def human_name
      humanize(name)
    end
 end



 <%= f.collection_select :role_id, @role, :id, :human_name%>

Upvotes: 3

Related Questions