<% form_for :credit_card, @cc, :url => '/credit_cards', :method => :post do |f| %>
<%= f.hidden_field "job_id", :value => params[:job_type_id] %>
<%= f.hidden_field "job_type", :value => "Job Hourly" %>
<%= f.hidden_field "lead_id", :value => @job.lead_id %>
<center><strong>ADD New Credit Card</strong> </center>
<br/>
<table align="left">
<tr>
<td> <label style="padding-left: 30px;">Type</label></td>
<td><%= f.select(:card_type, CreditCard::TYPES, {:prompt => "Select Type", :selected => ""}) %></td>
</tr>
<tr>
<td> <label style="padding-left: 30px;">Number</label></td>
<td><%= f.text_field "card_number", "size" => 16, 'maxlength' => 16%></td>
</tr>
<tr>
<td> <label style="padding-left: 30px;">Expiry</label></td>
<td> <select id="cc_state" name="credit_card[expiration_month]">
<%= options_for_select( [[ "Select Month", "" ]] + CreditCard::MONTHS )%>
</select>
<select id="cc_state" name="credit_card[expiration_year]">
<%= options_for_select( [[ "Select Year", "" ]] + ((Date.today.year - 5)..(Date.today.year + 12)).collect{|x| [x,x]}.reverse )%>
</select>
</td>
</td>
</tr>
<tr>
<td> <label style="padding-left: 30px;">CVV</label></td>
<td><%= f.text_field "security_code", "size" => 4, 'maxlength' => 4%></td>
</tr>
<tr>
<td> <label style="padding-left: 30px;">Expiry</label></td>
<td> <select id="cc_state" name="credit_card[expiration_year]">
<%= options_for_select( [[ "Select Year", "" ]] + ((Date.today.year - 5)..(Date.today.year + 12)).collect{|x| [x,x]}.reverse )%>
</select>
</td>
</tr>
<tr>
<td> <label style="padding-left: 30px;">Location</label></td>
<td><%= f.select(:id, @job_extra_stops.collect{|s| ["#{s.city},#{s.zip},#{s.state}", s.id]},:onchange => "display_dropdown(this)",:id => "dropdown_id", :prompt => "Select Location")%> </td>
</tr>
<tr><td> <label style="padding-left: 30px;">Street</label></td>
<td><%= f.text_field "billing_street_address", "size" => 20 %></td></tr>
<tr><td> <label style="padding-left: 30px;">City</label></td>
<td><%= f.text_field "billing_city", "size" => 20 %></td></tr>
<tr><td> <label style="padding-left: 30px;">State</label></td>
<td><select id="cc_state" name="credit_card[billing_state]">
<%= options_for_select( [[ "Select State", "" ]] + State::NAMES )%>
</select></tr>
<tr><td> <label style="padding-left: 30px;">Zip</label></td>
<td><%= f.text_field :billing_zip, "size" => 12 %></td></tr>
<tr>
<td colspan="2" align="center"><%= submit_tag 'Save' %></td>
</tr>
这是视图文件中的代码。目前信用卡模型属性是在表单中手动输入然后保存的。但是我不想手动输入,而是想导入那些已经存在于 job_extra_stop 模型中的属性值。从下拉列表中选择该选项时,我想将下拉列表的那些值(来自 job_extra_stop 模型)映射到信用卡模型属性
这意味着当我选择特定选项时,state、zip、city 的值应显示在文本框中的下方,并在提交后保存在 credit_card 模型中。
我正在使用 rails 1.2.2 和 ruby 1.8.6
谢谢