Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法';型号名称';对于ActiveMerchant::账单::信用卡:类_Ruby On Rails_Ruby_Credit Card_Activemerchant - Fatal编程技术网

Ruby on rails 未定义的方法';型号名称';对于ActiveMerchant::账单::信用卡:类

Ruby on rails 未定义的方法';型号名称';对于ActiveMerchant::账单::信用卡:类,ruby-on-rails,ruby,credit-card,activemerchant,Ruby On Rails,Ruby,Credit Card,Activemerchant,我正在尝试实现一个用户可以购买物品的表单。要做到这一点,他们需要使用信用卡。为了帮助他们,我安装了ActiveMerchant gem。这是我的信用卡表格 <%= form_for @credit_card do |f| %> <div class = "inner-form"> <p class = "heading">Payment Information</p> <p> <%= f.label :car

我正在尝试实现一个用户可以购买物品的表单。要做到这一点,他们需要使用信用卡。为了帮助他们,我安装了ActiveMerchant gem。这是我的信用卡表格

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

<div class = "inner-form">

  <p class = "heading">Payment Information</p>

  <p>
    <%= f.label :card_type, "Card Type:*" %></br>
    <%= select_tag(:card_type, options_for_select([['Visa', 1], ['MasterCard', 2], ['American Express', 3], ['Discover', 4]])) %>
  </p>

  <p>
    <%= f.label :card_number, "Card Number:*" %></br>
    <%= f.text_field :card_number %>
  </p>

  <p>
    <%= f.label :card_verification, "Security Code:*" %></br>
    <%= f.text_field :card_verification %>
  </p>

  <p>
    <%= f.label :card_expires_on, "Expiration Date:*" %></br>
    <%= select_tag(:card_expires_on, options_for_select([['01-January', 1], ['02-February', 2], ['03-March', 3], ['04-April', 4], ['05-May', 5],
    ['06-June', 6], ['07-July', 7], ['08-August', 8], ['09-September', 9], ['10-October', 10], ['11-November', 11], ['12-December', 12]])) %>
    <%= select_tag(:card_expires_on, options_for_select([['2014', 1], ['2015', 2], ['2016', 3], ['2017', 4], ['2018', 5], ['2019', 6], ['2020', 7],
    ['2021', 8], ['2022', 9], ['2023', 10], ['2024', 11], ['2025', 12], ['2026', 13], ['2027', 14], ['2028', 15], ['2029', 16], ['2030', 17]])) %>
  </p>

  <%= f.submit "Charge My Credit Card and Process My Order", :class => "add-to-cart" %></br></br>
我已安装最新版本的ActiveMerchant(1.45)


此错误消息没有为我提供解决此问题的大量信息

ActiveMerchant::Billing::CreditCard
对象不能用于
表单中,除非您对类进行猴子补丁。

一种解决方案是使用
form\u for:credit\u card

您可能正在使用
form\u for
builder,其参数为
ActiveMerchant::Billing::CreditCard
对象
form\u for
希望其参数的类定义
model\u name
是的,我的代码格式不正确,所以我将form\u保留为第行
class CreditCardsController < ApplicationController

  def new
    @credit_card = ActiveMerchant::Billing::CreditCard.new
  end

  def create
    @credit_card = ActiveMerchant::Billing::CreditCard.new(credit_card_params)
    if @credit_card.save
      flash[:notice] = "Thank you for your purchase!"
      redirect_to root_path
    else
      flash[:danger] = "You have entered invalid information"
      redirect_to :back
    end
  end

  private

  def credit_card_params
    params.require(:credit_card).permit(:card_type, :card_number, :card_verification, :card_expires_on)
  end

end
class CreditCard < ActiveRecord::Base

  attr_accessor :card_number, :card_verification

  validate :validate_card, on: :create

  private

  def validate_card
    unless credit_card.valid?
      credit_card.errors.full_messages.each { |message| errors[:base] << "error" }
    end
  end

  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,s
      :first_name => first_name,
      :last_name => last_name
    )
  end

end
NoMethodError in CreditCards#new

undefined method 'model_name' for ActiveMerchant::Billing::CreditCard:Class