Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple_form collection labels

I want to use labels for collection items (for example, their translations).

= simple_form_for(@client) do |f|
  = f.error_notification
    .form-inputs
      = f.input :name, label: t('client.name')
      = f.input :level, collection: ['a', 'b', 'c'],
        label_method: ????
        label: t('client.level')
    .form-actions
      = f.button :submit, value: t('client.submit')

I am trying to figure out, what to use for label_method above. I would like to have label_method to map to translations as in map {|s| t("client.#{s}")}.

like image 570
Alexei Danchenkov Avatar asked May 23 '12 21:05

Alexei Danchenkov


1 Answers

If you don't already have a label method, you can pass a lambda to get the result you want

label_method: ->(obj){ t("client.#{obj}") }
like image 98
DVG Avatar answered Oct 17 '22 22:10

DVG