Ruby On Rails Active Admin has_many更改下拉列表以使用其他列 [英] Ruby On Rails Active Admin has_many changing dropdown to use a different column

查看:69
本文介绍了Ruby On Rails Active Admin has_many更改下拉列表以使用其他列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ActiveAdmin和RoR完全陌生,我不知道如何更改has_many关联中下拉列表的可见值。

I am completely new to ActiveAdmin and RoR and i cant figure out how to change the visible value of the dropdowns in a has_many association.

class Fillup < ActiveRecord::Base
    // key is car_id:integer
    belongs_to :car
end



汽车型号



Car Model

class Car < ActiveRecord::Base
    validates :description, :presence => true
    key is fillup_id:integer
    has_many :fillups
end



当前显示的内容:



当前显示的是im假设已编码对分配给它的Car的引用。

What it currently shows:

It currently shows im assuming an encoded reference to the Car assigned to it.

我需要它显示给定的描述,该描述定义为 description:string 汽车模型

I need it to show the description given which is defined as description:string in the Car Model.

推荐答案

类似的东西应该可以工作...

Something like this should work...

app / admin / model_name.rb

form do |f|
  f.inputs "My Model Name" do
    # add your other inputs
    f.input :cars, :collection => Car.all.map{ |car| [car.description, car.id] }
    f.buttons
  end 
end

阅读本文以了解有关修改表单的更多信息。

Read this article to learn more about modifying the form.

AciveAdmin使用 formtastic ,您也应该阅读有关内容。

AciveAdmin uses formtastic, you should read about that as well.

这篇关于Ruby On Rails Active Admin has_many更改下拉列表以使用其他列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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