阻止 Rails 表单标签修改文本 [英] Stop Rails form label from modifying text

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

问题描述

我的其中一个视图中有以下代码,但它始终呈现为主页 url.我怎样才能阻止它改变案例?

I have the code below in one of my views but it always renders as Home page url. How can I stop it from changing the case?

    <%= f.label "Home Page URL" %><br />

推荐答案

<%= f.label :home_page_url, "Home Page URL" %><br />

傻,我知道,但那行了.

Silly, I know, but that'll do it.

f.label 之后的第一个参数实际上应该是被编辑对象的方法,所以你可能弄错了.在我上面的重写中,我假设方法(字段名称)实际上是home_page_url".第二个参数是可选的,将覆盖 Rails 的方法名称的默认大小写 - 这就是您想要放入正确大小写标签的位置.

The first parm after f.label should actually be the method of the object being edited, so you've probably got that wrong. I'm assuming the method (field name) is actually "home_page_url" in my rewrite above. The second parm, optional, will override Rails' default case-ing of the method name - that's where you want to put in your properly-cased label.

这篇关于阻止 Rails 表单标签修改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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