2010-03-12 69 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