나는 적극적인 관리자와 money - https://github.com/RubyMoney/money 보석을 사용하고 있습니다. 돈 보석에 의해 처리되는 속성이 있습니다.적극적인 관리자와 비용
돈 보석은 센트로 값을 저장합니다. 활성 admin으로 항목을 만들면 DB에 올바른 값이 생성됩니다 (50.00은 5000).
그러나 항목을 편집 할 때 값에 100이 곱해집니다. 즉, 50.00의 원래 입력에 대해 AA 디스플레이 5000을 의미합니다. 내가 돈 속성을 가지고 뭔가를 편집하면 100으로 배가 될 것입니다. 생성시, 값은 돈 로직을 거치지 만 편집에서는 어떻게 든 활성화 된 관리자가 최종 금전적 가치 대신 센트를 표시하는 부분을 건너 뜁니다. 액티브 관리자와 함께 돈을 사용하는 방법이 있습니까?
예 :
form :html => { :enctype => "multipart/form-data"} do |f|
f.inputs "Products" do
......
f.has_many :pricings do |p|
p.input :price
p.input :_destroy, :as => :boolean,:label=>"Effacer"
end
f.actions :publish
end
모델 :
# encoding: utf-8
class Pricing < ActiveRecord::Base
belongs_to :priceable, :polymorphic => true
attr_accessible :price
composed_of :price,
:class_name => "Money",
:mapping => [%w(price cents), %w(currency currency_as_string)],
:constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) },
:converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") }
end
https://github.com/collectiveidea/money 또는 https://github.com/RubyMoney/money에서 돈을 보석으로 연결되는 링크를 제공 할 수 있습니까? 또한 모델의 소스 코드가 좋을 것입니다. – Fivell