【问题标题】:Rails Form using Foundation: adding placeholder text [closed]使用 Foundation 的 Rails 表单:添加占位符文本 [关闭]
【发布时间】:2014-06-11 16:00:52
【问题描述】:

我将 Foundation 用于我的 Rails 表单并使用说明:http://foundation.zurb.com/docs/components/forms.html

我无法显示占位符文本。

我的查看代码:

<div class="field">
  <h2>Personal Information</h2>
  <%= f.label :full_name %><br>
  <%= f.text_field :full_name, placeholder="Please enter first last and initial."%>
</div>

【问题讨论】:

  • 你应该这样做placeholder:而不是placeholder=

标签: css ruby-on-rails ruby forms


【解决方案1】:

您的语法不正确。检查 here 以了解 Rails 方式。 Rails 输入字段的语法与 HTML 标记不同。您有两种选择:

<%= f.text_field :full_name, placeholder: "Please enter first last and initial" %>

<%= f.text_field :full_name, :placeholder => "Please enter first last and initial" %>

【讨论】:

  • 很好,成功了!谢谢您的帮助! (这里是新程序员)。
【解决方案2】:

为了稍微扩展 Justin 的回答,请记住 ERB 的 &lt;% %&gt; 标记之间的所有内容都是 Ruby。

虽然一开始可能感觉 Ruby 以 full_name 结尾,但您真正在做的是调用带参数的方法:

f.text_field(:full_name, placeholder: "Please enter first last and initial.")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 2016-05-28
    • 2015-12-15
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多