将html参数放入Rails数组参数

时间:2014-07-15 19:54:15

标签: javascript ruby-on-rails ruby

Ruby on Rails 4.1

表单在POST完成后将参数放入数组中。我正在制作一个脚本来自动填写与送货地址相同的帐单邮寄地址。脚本运行时,它将值指定为html值。

如何将这些值放入正在发送的付款数组中?

cc_name和ship_name在支付数组之外的日志,我希望它们在里面:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"x", "cc_name"=>"Bobby", "payment"=>{"telephone"=>"555", "email"=>"drfernandez1@yahoo.com", "address1"=>"641 W Rt 66", "address2"=>"", "city"=>"Glendora", "state"=>"CA", "postal_code"=>"91740", "country"=>"USA", "cc_type"=>"Visa", "cc_number"=>"5555555588884444", "ccv"=>"321", "expires_on(1i)"=>"2014", "expires_on(2i)"=>"9", "expires_on(3i)"=>"1", "ship_address1"=>"641 W Route 66", "ship_address2"=>"", "ship_city"=>"Glendora", "ship_state"=>"c", "ship_postal_code"=>"91740", "ship_country"=>"u", "card_holder_auth"=>"1", "charge_auth"=>"1", "name_auth"=>"David Duke", "date_auth"=>"7"}, "billingtoo"=>"on", "ship_name"=>"Bobby", "commit"=>"Send Payment"}

表格(减去杂乱):

<%= form_for @payment do |f| %>

<%= render 'shared/payment_error_messages' %>

<h1>Fill in all blank areas with payment information:</h1>
<div class="col-md-5 col-md-offset-1">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">Applicant Information</h3>
        </div>
        <div class="panel-body">
        <%= f.label :cc_name, "Name as it appears on credit card:" %><br>
        <%= f.text_field :cc_name, class: "input-lg", :name => "cc_name" %> <%#= @payment.errors.get(:cc_name) %>

        <%= f.label :telephone, "Telephone Number:" %><br>
        <%= f.text_field :telephone, class: "input-lg" %>
        ...
        <div class="panel-body">
        <input type="checkbox" name="billingtoo" onclick="FillBilling(this.form)"><em>Shipping Address is the same as the Billing Address</em>
        <p>Please Note: This cannot be a P.O box address</p>

        <%= f.label :ship_name, "Name:" %><br>
        <%= f.text_field :ship_name, class: "input-lg", :name => "ship_name" %>

        <%= f.label :ship_address1, "Address 1:" %><br>
        <%= f.text_field :ship_address1, class: "input-lg" %>
        ...

        <%= f.submit "Send Payment", class: "btn btn-lg btn-primary", id: "commit" %>
        </div>
    </div>
</div>
<% end %>
<br/>
<%= link_to 'Back', session[:last_page] %>
</div>

<script>
function FillBilling(f) {
  if(f.billingtoo.checked == true) {
  f.ship_name.value = f.cc_name.value;

  }
}
</script>

1 个答案:

答案 0 :(得分:1)

您正在覆盖该字段的名称:

:name => "cc_name"

这就是为什么它被发送到阵列之外的原因。请尝试删除:name分配:

<%= f.text_field :cc_name, class: "input-lg" %>

<%= f.text_field :ship_name, class: "input-lg" %>