simple_form collection labels

牧云@^-^@ 提交于 2019-12-22 01:56:26

问题


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}")}.


回答1:


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}") }


来源:https://stackoverflow.com/questions/10728461/simple-form-collection-labels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!