How to modify rails_admin edit view

2019-07-21 04:15发布

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条回答
干净又极端
2楼-- · 2019-07-21 04:52

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.

查看更多
登录 后发表回答