Globalizing Currency... last line

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 :

Prix (en euros)
<%= text_field 'product', 'lp' %>

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs