ruby on rails - Retrieving contact details from contact id using collection select -
i utilize next collection select allow users pick contact name.
<div class="form-group"> <%= f.label :contact %> <%= f.collection_select(:contact, current_user.contacts.all, :id, :name, prompt: true, class: "form-control") %> </div>
but, instead of name, it's id that's displayed when utilize email.contact
in show page. have tried using email.contact.name , returns nomethoderror. associations, email has_many contacts , contacts belongs_to email. tried using inverse_of these association, still unable retrieve contact name. there workaround solve this?
if @ collection_select
collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
if @ docs says
the :value_method , :text_method parameters methods called on each fellow member of collection. homecoming values used value attribute , contents of each tag, respectively.
so need pass value_method method want save in db, right using id. save name can this:
<%= f.collection_select(:contact, current_user.contacts.all, :name, :name, prompt: true, class: "form-control") %>
ruby-on-rails
No comments:
Post a Comment