- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在观看 Ryan Bates 关于 Active Merchant 集成视频 Railscast #145 的视频,我的问题是关于他在 Order.rb 方法中定义的 @credit_card 方法的创建。
def credit_card
@credit_card||=ActiveMerchant::Billing::CreditCard.new(
:type=>card_type,
:number=>card_number,
:verification_value=>card_verification,
:month=>card_expires_on.month,
:year=>card_expires_on.year,
:first_name=>first_name,
:last_name=>last_name
)
结束
我不了解的是如何调用此方法。新方法中的 form_for 创建了一个 @order 对象,而没有提及 credit_card 方法。如何调用 credit_card 方法来启动 @credit_card 对象的创建。
我知道虚拟属性,但我不知道 credit_card 方法实际上是如何调用的。
最佳答案
查看截屏代码 here .
在 app/views/orders/new.html.erb
我们可以看到订单,从第一行开始
<% form_for @order do |f| %>
我们看到,在提交时,表单使用 oders_controller 创建方法。
在 app/controller/orders_controller.rb
def create
@order = current_cart.build_order(params[:order])
@order.ip_address = request.remote_ip
if @order.save
if @order.purchase
render :action => "success"
else
render :action => "failure"
end
else
render :action => 'new'
end
end
我们可以看到 @order 是从购物车构建的 Order 实例。这里没什么特别的此订单现在使用 @order.save
保存,然后在 @order 上调用购买方法
一起来看看这个购买方式吧!
在 app/model/order.rb 中
def purchase
response = GATEWAY.purchase(price_in_cents, credit_card, purchase_options)
transactions.create!(:action => "purchase", :amount => price_in_cents, :response => response)
cart.update_attribute(:purchased_at, Time.now) if response.success?
response.success?
end
第二行 response = GATEWAY.purchase(price_in_cents, credit_card, purchase_options)
。 credit_card 方法作为 GATEWAY.purchase 的参数被调用
关于ruby-on-rails - 关于在 Ryan bates Active_Merchant 集成视频中创建信用卡对象的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1697500/
我正在观看 Ryan Bates 关于 Active Merchant 集成视频 Railscast #145 的视频,我的问题是关于他在 Order.rb 方法中定义的 @credit_card 方
我正在关注 http://railscasts.com/episodes/145-integrating-active-merchant 如何设置配置设置以与 Rails 3 应用程序兼容。 我尝试将
我正在使用 Rails 3 开发一个基于订阅的网站,我需要使用 PayPal Express Checkout(英国)进行定期付款。我发现 ActiveMerchant 默认不支持它,所以我看到了以下
我是一名优秀的程序员,十分优秀!