Ruby on rails 由&;字段
因此,我已经阅读并重读了朱棣文(Stephen Chu)关于这个主题的文章(),但是我没有任何运气 根据money gem文档money.rubyforge.org中提供的示例 型号Ruby on rails 由&;字段,ruby-on-rails,fields-for,Ruby On Rails,Fields For,因此,我已经阅读并重读了朱棣文(Stephen Chu)关于这个主题的文章(),但是我没有任何运气 根据money gem文档money.rubyforge.org中提供的示例 型号 class Payment < ActiveRecord::Base composed_of :amount, :class_name => "Money", :mapping => [%w(cents cents), %w(currency currency_as_strin
class Payment < ActiveRecord::Base
composed_of :amount,
:class_name => "Money",
:mapping => [%w(cents cents), %w(currency currency_as_string)],
:constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) }
end
我收到的错误是:
{“美分”=>“6.66”,“货币”=>“美元”}的未定义方法“美分”:hashWithInferenceAccess
“amount”散列被作为“cents”传递到composited_中,但根据文章,它应该在表单的params中使用“amount”属性。编辑:我以前误解了你的问题。是的,在您的表格中,您需要通过以下方式引用
金额
:
- form_for @payment do |p|
= a.label :dollars
= a.text_field :amount
= a.label :currency
= a.text_field :currency, :value => :usd
- form_for @payment do |p|
- p.fields_for :amount, @payment.amount do |a|
= a.label :cents
= a.text_field :cents
= a.label :currency
= a.text_field :currency, :value => :usd
- form_for @payment do |p|
= a.label :dollars
= a.text_field :amount
= a.label :currency
= a.text_field :currency, :value => :usd