开发者

Is there an easy way to humanize string in collection_select?

开发者 https://www.devze.com 2023-03-06 19:28 出处:网络
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 human开发者_

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 human开发者_如何学编程ize(:name) but that didn't seem to work.


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%>
0

精彩评论

暂无评论...
验证码 换一张
取 消