问题
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