ruby on rails - human attribute name in a partial for a form_for -
i have shared partial i'm using in various form_for tags so:
<%= render 'shared/text_field_attribute', :f => f, :attribute => :some_attr, :predicate => 'is/starts with/ends with/etc.' %>
app/views/shared/text_field_attribute.html.erb looks this:
<div class="form-group"> <%= f.label attribute, "#{attribute} #{predicate}", class: 'sr-only' %> <%= f.text_field attribute, class: 'form-control', placeholder: "#{f.object.class.human_attribute_name(attribute)} #{predicate}…" %> </div>
is there more concise human attribute name?
f.object.class.human_attribute_name(attribute)
instead of:
f.object.class.human_attribute_name(attribute)
you can use humanize
method so:
attribute.to_s.humanize
Comments
Post a Comment