加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Ruby On Rails Active Admin has_many更改下拉

发布时间:2020-12-17 04:05:42 所属栏目:百科 来源:网络整理
导读:我是ActiveAdmin和RoR的新手,我无法弄清楚如何在has_many关联中更改下拉列表的可见值. 填充模型 class Fillup ActiveRecord::Base // key is car_id:integer belongs_to :carend 汽车模型 class Car ActiveRecord::Base validates :description,:presence =
我是ActiveAdmin和RoR的新手,我无法弄清楚如何在has_many关联中更改下拉列表的可见值.

填充模型

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

汽车模型

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

它目前显示的内容:

它目前显示我假设对分配给它的Car的编码引用.

我需要它来表明:

我需要它来显示给定的描述,其定义为描述:汽车模型中的字符串.

解决方法

像这样的东西应该工作……

在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

阅读this article以了解有关修改表单的更多信息.

AciveAdmin使用formtastic,你也应该阅读它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读