我正在尝试使用哈希来显示表单:
PREFIX_STR = "Prefix"
FIRST_STR = "First Name"
NEW_USER_HASH = Hash.new
NEW_USER_HASH[ "prefix" ] = { "label" => PREFIX_STR, "type" => "text_field" }
NEW_USER_HASH[ "first" ] = { "label" => FIRST_STR, "type" => "text_field" }
在 new.html.erb 中,我有:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<% NEW_USER_HASH.each do |column_name,field_info| %>
<div class="field">
<%= f.label field_info["label"] %>
<%= f.text_field column_name %>
</div>
<% end %>
这很好用,但我希望它不是 f.text_field,而是 field_info [“type”] 中的内容。我试过的都没有用。有任何想法吗?
谢谢