How to modify rails_admin edit view

倾然丶 夕夏残阳落幕 提交于 2019-12-12 21:39:44

问题


I have a Contact class associated with User class as follows

class Contact < ActiveRecord::Base
   belongs_to :users
end

In my edit I want to show a dropdown with list of user name as options that component should bind with contact.user_id.

How to achieve this?


回答1:


There are a number of ways to achieve this, here is one example.

<%= f.select :user_id, Contact.all.collect{|c| [c.user.name, c.user.id]} %>

This creates an array of contact.user.name and contact.user.id and submits the selected contact based on the associated user_id to your controller.

You will find more information here.



来源:https://stackoverflow.com/questions/14103224/how-to-modify-rails-admin-edit-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!