form_for 不大写

发布于 2024-10-27 16:07:57 字数 876 浏览 0 评论 0原文

该视图不将名字和姓氏大写。它们都以小写形式存储在数据库中。 在模型中,我对first_name和last_name有以下getter:

def first_name
    string_to_return = read_attribute(:first_name)
    return string_to_return.capitalize if string_to_return != nil && !string_to_return.strip.empty?
    return "N/A"

所以我希望在视图中first_name显示为大写,但是,当我编辑配置文件时,它以小写形式显示,我使用form_for,代码如下:

<%= form_for(@profile, :url=>{:action=>'update'}, :html => {:multipart => true}) do |f| %>
 <div class="field">
    <%= f.label :first_name %><br />
    <%= (f.text_field (:first_name)).capitalize %>
  </div>
  <div class="field">
    <%= f.label :last_name %><br />
    <%= (f.text_field (:last_name))%>
  </div>
<%end%>

我尝试了所有括号的组合但没有成功,我尝试在视图中使用和不使用大写函数,但结果总是相同的:DOWNCASE

有什么建议吗? 总氮

The view doesen't capitalize first_name and last_name. Both of them are stored in downcase inside the db.
In the model I have the following getters either for first_name and last_name:

def first_name
    string_to_return = read_attribute(:first_name)
    return string_to_return.capitalize if string_to_return != nil && !string_to_return.strip.empty?
    return "N/A"

So I expect that in the view the first_name appear capitalized, but instead, when I edit the profile it appears in downcase, I use a form_for, the code is the following:

<%= form_for(@profile, :url=>{:action=>'update'}, :html => {:multipart => true}) do |f| %>
 <div class="field">
    <%= f.label :first_name %><br />
    <%= (f.text_field (:first_name)).capitalize %>
  </div>
  <div class="field">
    <%= f.label :last_name %><br />
    <%= (f.text_field (:last_name))%>
  </div>
<%end%>

I tried all the combinations of parenthesis without success, I tried to use and not use the capitalize function in the view but the result it's always the same: DOWNCASE

Any suggestion ?
Tnx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您的好友蓝忘机已上羡 2024-11-03 16:07:57

为什么你只用小写字母存储?这是有原因的吗?如果你真的必须在后端小写,我假设你只想在前端大写。如果是这种情况,您不需要在后端使用大写函数。它应该在前端完成(因为你大写的原因只是为了美观)

这可以通过以下方式在CSS中轻松实现:

input {
  text-transform: capitalize;
}

why are you storing in downcase only? is there a reason for this? if you really have to downcase in the backend, im assuming that you just want to capitalize in the front end. if that is the case, you don't need your capitalize function in your backend. it should be done in the FRONT END(since your reason for capitalizing is for aesthetics only)

That could easily be achieved in the css by:

input {
  text-transform: capitalize;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文