【问题标题】:rendering specific fields with Rails使用 Rails 渲染特定字段
【发布时间】:2010-03-12 07:51:40
【问题描述】:

如果我有一个对象说

@user

我只想渲染其中的某些字段,比如 first_name 和 last_name(我正在使用 AMF)

render :amf => @user

例如,我有一个 @user 属性,它是“dob”(出生日期)我想在控制器业务逻辑中使用它,但我不想将它发送给客户端(在本例中为 Flex ) 我可以在渲染之前做这样的事情:

@user.dob = nil

但我认为必须有更好的方法来做到这一点。

我该怎么做?

我知道我可以在执行“查找”时使用 :select,但我需要在服务器端使用其他字段,但不想将它们与 AMF 一起发送到客户端,我不想这样做第二次“发现”

谢谢,

【问题讨论】:

  • 我们需要更多信息
  • 我添加了更多描述,希望对您有所帮助

标签: ruby-on-rails amf


【解决方案1】:

article 提供了该方法的详细信息。

您已将 config/rubyamf_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

【讨论】:

    猜你喜欢
    • 2014-03-19
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2021-10-16
    • 2015-01-07
    相关资源
    最近更新 更多