2010-03-12 76 views
0

如果我有一個對象說渲染使用Rails的特定字段

@user 

,我想只渲染某些領域中它說FIRST_NAME和姓氏(我使用AMF)

render :amf => @user 

對於實例我有@user屬性是'dob'(出生日期)我想在控制器業務邏輯中使用它,但我不想將它發送給客戶端(在這種情況下是Flex)我可以defenitaly在渲染前做這樣的事情:

@user.dob = nil 

但我認爲必須有一個更好的方式來做到這一點。

我該怎麼做?

我知道我可以使用:選擇做'找'時,但我需要使用服務器端的其他領域,但不希望與AMF發送給客戶端,我不想做第二個 '發現'

感謝,

+0

我們需要請 – shingara 2010-03-12 09:26:56

+0

我增加了更多的描述我希望這可以幫助更多信息 – Tam 2010-03-12 10:00:59

回答

1

article給出了方法的細節。

你必須配置配置/ ruby​​amf_config.rb文件,如下所示:

require 'app/configuration' 
module RubyAMF 
    module Configuration 
    ClassMappings.ignore_fields = ['created_at','updated_at'] 
    ClassMappings.translate_case = true 
    ClassMappings.assume_types = false 
    ParameterMappings.scaffolding = false 

    ClassMappings.register(
     :actionscript => 'User', 
     :ruby   => 'User', 
     :type   => 'active_record', 
     :associations => ["employees"], 
     :ignore_fields => ["dob"] 
     :attributes => ["id", "name", "location", "created_at", "updated_at"] 
    ) 

    ClassMappings.force_active_record_ids = true 
    ClassMappings.use_ruby_date_time = false 
    ClassMappings.use_array_collection = true 
    ClassMappings.check_for_associations = true 
    ParameterMappings.always_add_to_params = true 
    end 
end