为什么:placeholder会以一种形式像我想要的那样工作,而在Rails 3中却没有另一种形式?

问题描述

| 我在不同的地方有两种形式,它们产生两种不同的结果。我要发生的是页面加载,对于数据存在的某些字段,该表单会自动使用该数据填充表单-因此,如果用户按下提交而不在该字段中输入任何内容,它将提交正确的数据。 不起作用的是。
<%= form_for :transaction,:params => @result && @result.params[:transaction],:errors => @result && @result.errors.for(:transaction),:builder => ApplicationHelper::BraintreeFormBuilder,:url => Braintree::TransparentRedirect.url,:html => {:autocomplete => \"off\"} do |f| -%>
  <%#= field_set_tag \"Customer\" do -%>
    <%= f.fields_for :customer,@user do |c| -%>
      <div><%= c.text_field :first_name,:placeholder => :first_name %></div>
      <div><%= c.text_field :last_name,:placeholder => :last_name %></div>
      <div><%= c.text_field :email,:placeholder => :email %></div>
    <% end -%>

<% end %>
这样做的是:
<%= form_for(resource,:as => resource_name,:url => registration_path(resource_name),:html => { :method => :put }) do |f| %>

    <%= f.text_field :first_name,:placeholder => :first_name %><br />      
    <%= f.text_field :last_name,:placeholder => :last_name %><br />    
    <%= f.text_field :username,:placeholder => :username %><br />      
    <%= f.text_field :email,:placeholder => :email %><br />

    <%= f.password_field :password,:placeholder => \'Password\' %><span class=\"explanation\">(leave blank if you don\'t want to change it)</span><br />
    <%= f.password_field :password_confirmation,:placeholder => \'Password Confirmation\' %><br />
    <%= f.password_field :current_password,:placeholder => \'Current Password\' %><span class=\"explanation\">(we need your current password to confirm your changes)</span><br />

    <div class=\"settings_button\">       
            <%= link_to \"Cancel My Account\",registration_path(resource_name),:confirm => \"This will CANCEL your account and remove all projects and images. Are you sure?\",:method => :delete,:class => \"pill negative button\",:id => \"cancel-account\" %>
        <%= f.submit \"Update\",:class => \"primary button\",:id => \"update-account\" %>
    </div>

    <% end %>
您会注意到,他们两个都有
text_field :first_name,:placeholder => :first_name
,但只有第二种形式有效。 在该字段中的第一种形式分别在
:first_name
:last_name
字段中输出短语
first_name
last_name
。 有什么想法吗?     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)