simple_form 个标签的标题大小写
Title case for simple_form labels
下面的代码给出了"Project address"的标签:
%h2 New Project
= simple_form_for(@project, html: {class: "form-horizontal"}, wrapper: :horizontal_form) do |f|
= f.error_notification
= f.input :project_address, required: true
= f.button :submit, "Create"
除了使用 f.label
之外,还有什么方法可以制作标签标题大小写 ("Project Address") 吗?
如果你想对所有标签进行首字母大写,你可以在初始值设定项中配置简单形式:
# config/initializers/simple_form.rb
# How the label text should be generated altogether with the required text.
config.label_text = lambda { |label, required, explicit_label| "#{required} #{explicit_label ? label : label.to_s.titleize}" }
除非您使用 :label
选项明确指定标签,否则这将使您的所有标签成为标题。
下面的代码给出了"Project address"的标签:
%h2 New Project
= simple_form_for(@project, html: {class: "form-horizontal"}, wrapper: :horizontal_form) do |f|
= f.error_notification
= f.input :project_address, required: true
= f.button :submit, "Create"
除了使用 f.label
之外,还有什么方法可以制作标签标题大小写 ("Project Address") 吗?
如果你想对所有标签进行首字母大写,你可以在初始值设定项中配置简单形式:
# config/initializers/simple_form.rb
# How the label text should be generated altogether with the required text.
config.label_text = lambda { |label, required, explicit_label| "#{required} #{explicit_label ? label : label.to_s.titleize}" }
除非您使用 :label
选项明确指定标签,否则这将使您的所有标签成为标题。