I have a model
class PriceSet < ActiveRecord::Base
def price_type_description
case read_attribute(“price_type”)
when “P”
self[:price_type_description] = “Promotion”
when “F”
self[:price_type_description] = “Front L.”
else
self[:price_type_description] = “??”
end
end
end
using irb
ps=PriceSet.find(7)
=> #<PriceSet:0x44f0674 @attributes={“store_set_id”=>1, “vendor_id”=>10,
“price_
to_start_on”=>#<Date: 4907775/2,0,2299161>, “approved_by_user_id”=>nil,
“id”=>7,
“price_status”=>“C”, “approved_at”=>nil, “price_type”=>“F”,
“price_to_end_on”=>
#<Date: 4910755/2,0,2299161>}>ps.price_type
=> “F”ps.price_type_description
=> “Front L.”
Why does price_type_description not appear as one of the attributes?
I want price_type_description to be one of the attributes when I do a
find
on this class, can I do this?
So I can have both price_type and price_type_description in the xml
output
class PriceSetController < ApplicationController
def list
@price_set = PriceSet.find(:all,
:conditions => [“vendor_id = :vendor_id”,
params],
:order => “price_to_start_on, price_type,
price_status”)
render :xml => @price_set.to_xml
end
end
Thanks
Andrew