我需要在我正在撰写的表单上添加一个占位符。我尝试了以下内容,以及其他一些变化但没有成功:
<%= form_tag("/search", method: "get") do %>
<%= label_tag(:address, "Address:", placeholder: '100 Brooklyn Ave Unit 3' ) %>
<%= text_field_tag(:address) %>
<%= label_tag(:citystatezip, "City and State OR ZIP:", placeholder: 'New York, NY') %>
<%= text_field_tag(:citystatezip) %>
<%= submit_tag("Enter Address") %>
<% end %>
答案 0 :(得分:1)
您不会将占位符放在标签标记中,它们应放在输入字段中,在这种情况下为text_field_tag
:
<%= form_tag("/search", method: "get") do %>
<%= label_tag(:address, "Address:") %>
<%= text_field_tag(:address, nil, placeholder: '100 Brooklyn Ave Unit 3') %>
<%= label_tag(:citystatezip, "City and State OR ZIP:") %>
<%= text_field_tag(:citystatezip, nil, placeholder: 'New York, NY') %>
<%= submit_tag("Enter Address") %>
<% end %>