如何覆盖在rails_admin gem中的下拉列表中显示的值 [英] How to override value that appears in a dropdown in the rails_admin gem

查看:63
本文介绍了如何覆盖在rails_admin gem中的下拉列表中显示的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下内容的模型UserDelegation:

I have a model UserDelegation that contains:

belongs_to :delegator, :class_name => 'User'#, :conditions => {:order => 'users.last_name ASC, users.first_name ASC'}
belongs_to :delegatee, :class_name => 'User', :touch => true#, :conditions => {:order => 'users.last_name ASC, users.first_name ASC'}

在我的用户模型中,我有这个:

and in my user model i have this:

has_many :delegatees, :through => :user_delegatees, :order => 'users.last_name ASC, first_name ASC'
has_many :delegators, :through => :user_delegators, :order => 'last_name ASC, first_name ASC'

当我在rails admin中并转到用户委托"表并添加一个新的代理时,我会看到两个下拉列表,其中列出了用户名.我确实知道rails_admin在填充关联下拉列表时会默认使用name.

when i am in rails admin and go to the User delegation table and add a new one i get two drop downs which lists the users name. I do know that rails_admin uses name by default when it populates drop downs in associations.

我想知道的是如何覆盖这些下拉列表中显示的内容,以便例如让其显示用户名-用户位置"?

What i am wanting to know is how to override what is displayed in these drop downs so I could for example have it display 'user's name - user's location'?

推荐答案

User模型的object_label_method更改为rails_admin

class User < ActiveRecord::Base

  ...

  rails_admin do
    object_label_method :name_location
  end

  def name_location
    self.name + ' - ' + self.location
  end
end

这篇关于如何覆盖在rails_admin gem中的下拉列表中显示的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆