我正在创建一个与Recurly on Rails交互的表单。
我有这个观点和形式:
<h1><%= t('payments.edit') %> </h1>
<%= render(:partial => 'shared/new_recurly_form', :locals => {:success_url => "#{APP_URL}#{users_credit_card_path}"}) %>
<%= semantic_form_for current_user, :url => users_credit_card_path, :html => {:method => :put, :class => 'credit_card'} do |form| %>
<%= form.inputs do %>
<div class="field">
<%= form.label :name %>
<%= form.text_field :name %>
</div>
<div class="field">
<%= form.label :first_surname %>
<%= form.text_field :surnames %>
</div>
<div class="field">
<%= label_tag :number, "Credit Card Number " %>
<%= text_field_tag :number %>
</div>
<div class="field">
<%= label_tag :verification_value, "Security Code on Card (CVV)" %>
<%= text_field_tag :verification_value %>
</div>
<div class="field">
<%= label_tag :month, "Expiration month" %>
<%= select_month(Date.today, :use_month_numbers => true) %>
</div>
<div class="field">
<%= label_tag :year, "Expiration year" %>
<%= select_year(Date.today, :start_year => Time.now.year, :end_year => Time.now.year + 20) %>
</div>
<% end %>
<%= form.buttons do %>
<%= form.commit_button t('confirm') %>
<% end %>
<% end %>
及其各自的控制器,credit_card_controller.rb
class Users::CreditCardsController < ApplicationController
skip_before_filter :check_deactivated_user
protect_from_forgery :except => :create
def create
update
end
def edit
@user = current_user
@price_plan = current_user.price_plans.active.first
end
def update
begin
update_new_recurly_subscription
rescue Exceptions::RecurlyAccountCreateInvalidAccountException => e
puts "CreditCardsController Exceptions::RecurlyAccountCreateInvalidAccountException"
puts e.message
rescue Recurly::Resource::NotFound => e
puts "CreditCardsController Recurly::Resource::NotFound Creating new account for user"
puts e.message
begin
create_new_recurly_account
create_new_recurly_subscription
rescue Exceptions::RecurlyAccountCreateInvalidAccountException => e
puts "CreditCardsController inside find Recurly::Resource::NotFound"
puts e.message
update_new_recurly_account
create_new_recurly_subscription
end
end
account = update_account_billing_info
account.billing_info = {
:first_name => current_user.name,
:last_name => "#{current_user.surnames}",
:number => params[:number],
:verification_value => params[:verification_value],
:month => params[:month],
:year => params[:year]
}
puts "Users::CreditCardsController update Billing info: #{account.billing_info.inspect}"
account.billing_info.save
if current_user.credit_card_store!(account.billing_info)
if current_user.is_debtor?
flash[:alert] = t('flash.price_plans.payed_after_unpay')
render :edit
else
flash[:alert] = t('flash.credit_card.update.success')
render :success
end
else
flash[:failure] = t('flash.credit_card.update.failure')
render :edit
end
end
end
当我更新表格时,使用前控制器上的更新功能,我可以更改信用卡号码,但我无法更改到期月份和到期年份。
我在这里缺少什么?为什么我可以更改信用卡号码而不是与Recurly交互的月份和年份?
答案 0 :(得分:0)
您正在提取不正确的参数(零值)。根据您的日志,尝试:
account.billing_info = {
...
:month => params[:date][:month],
:year => params[:date][:year]
}
对应"date"=>{"month"=>"7", "year"=>"2017"}