hey,
i want to accomplish something like this, i have a product and 3
languages for that product.
ex.
product
--------
id price stock
1 12.50 10
productlang
------------
id parent name lang
1 1 book en
2 1 boek nl
3 1 livre fr
but when i want to get the product item, i need to also get the
productlang, so this mean it is a sort of encapsulating, and i dont what
that,
See my other topic http://www.ruby-forum.com/topic/79385#new
my current structure is like this
id int(11) Nee auto_increment
name_en varchar(100) utf8_general_ci Nee
name_fr varchar(100) utf8_general_ci Nee
name_nl varchar(100) utf8_general_ci Nee
price decimal(10,2) Nee 0.00
and when i want the name in a certain language i do it like this:
class ApplicationController < ActionController::Base
before_filter :set_frontend_language
after_filter :clear_frontend_language
def set_frontend_language
Product.language = getFrontendLanguage()
end
def clear_frontend_language
Product.language = nil
end
end
class Product < ActiveRecord::Base
cattr_accessor :language
def to_s
return self.name
end
def name
case self.language
when "nl"
return self.name_nl
when "en"
return self.name_en
when "fr"
return self.name_fr
end
end
end
This is now my problem, what if i want to copy the language field from
the default (ex. EN) to an other language ( ex .NL), i wrote this
funtion in my product controller. In need to do this for each virtual
field like "name", so this can become big, and i dont want to repeat
myself.
def copy_lang
product = Product.find(params[:id])
from_lang = params[:from_lang]
to_lang = params[:to_lang]
from_text = nil
case from_lang
when "nl"
from_text = product.name_nl
when "en"
from_text = product.name_en
when "fr"
from_text = product.name_fr
end
case to_lang
when "nl"
product.name_nl = from_text
when "en"
product.name_en = from_text
when "fr"
product.name_fr = from_text
end
product.save
redirect_to :action => ''edit'', :id => product
end
Does anyone has a clean solution for this? or a proper way to do this so
i can do the virtual fields automatic?? Or use the object with his
objectlanguages idea...
Thx
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---