我如何添加一个新的变量来设计

时间:2015-04-23 15:39:24

标签: ruby-on-rails ruby devise

我正在使用Devise。我想添加一个动态变量。

class User < ActiveRecord::Base

  acts_as_token_authenticatable
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :omniauthable , :currencies_supported

  def currencies_supported
    Stripe.api_key = access_code
    @currencies_supported = ""
    begin
     last_currency = 'cad'
     all = Stripe::Account.retrieve().currencies_supported
     default_currency = Stripe::Account.retrieve().default_currency
     primary_currencies = [last_currency, default_currency, 'usd', 'eur', 'cad'].uniq

     @currencies_supported = primary_currencies + (all - primary_currencies)

    rescue Stripe::CardError => e

    rescue Stripe::InvalidRequestError => e
      p e
    rescue Stripe::AuthenticationError => e
       p e
    rescue Stripe::APIConnectionError => e
       p e
    rescue Stripe::StripeError => e
       p e
    rescue => e
      p e
    end

  end
end

我试过了

  

const_get&#39 ;:未初始化的常量Devise :: Models :: CurrenciesSupported(NameError)       来自/Users/Michelin/.rvm

1 个答案:

答案 0 :(得分:0)

这可能是你想要的,

attr_accessor :currencies_supported

:currencies_supported

中删除devise