| it's quite running smoothly... at least I get correct prices in local format...
but I cannot yet create or update it :
my Product model is defined as following :
class Product < ActiveRecord::Base
composed_of :price, :class_name => "Globalize::Currency", :mapping => [ %w(price cents) ]
attr_accessor :lp #not stored in DB, used to display formatted price in form
the form as following :
<p><label for="">Prix (en euros)</label><br/> <%= text_field 'product', 'lp' %></p>
and the controller
def new @product = Product.new @product.price = Currency.parse(0).format end
def create @product = Product.new(@params[:product]) if @product.save .....
def edit @product = Product.find(@params[:id]) @product.lp = @product.price.format end
def update @product = Product.find(@params[:id]) @product.price = Currency.parse(@params[:lp]) if @product.update_attributes(@params[:product]) ..... else render_action 'edit' end end
when trying to create a new Product I get the message : undefined method `cents' for "0,00 €":String
when modifying an existing price in DB .... there is no update !
what's wrong... ??
thanks
kad
|