simple_form 集合标签 [英] simple_form collection labels

查看:41
本文介绍了simple_form 集合标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为收藏品使用标签(例如,它们的翻译).

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')

我想弄清楚,上面的 label_method 使用什么.我想让 label_method 映射到翻译,如 map {|s|t("client.#{s}")}.

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

推荐答案

如果你还没有标签方法,你可以传递一个 lambda 来得到你想要的结果

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

这篇关于simple_form 集合标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆