Note that there are some explanatory texts on larger screens.

plurals
  1. POAssosiation help in ruby on rails
    primarykey
    data
    text
    <p>I have fully linked everything together so a contact <code>belongs_to :company</code> and a company <code>has_many :contacts</code> everything works. The only question i have is in the contacts#new form you have to enter a companies ID is it possible to input the name of the company somehow and for it too translate to an ID in the back end? at the moment my form looks like this. You may notice company_id at the bottom of the form this is the field which i want to change. So that it is more user friendly instead of inserting an ID you insert a name or some kind of list of companies that you select. Please help?</p> <pre><code>&lt;%= form_for(@contact) do |f| %&gt; &lt;% if @contact.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;h2&gt;&lt;%= pluralize(@contact.errors.count, "error") %&gt; prohibited this contact from being saved:&lt;/h2&gt; &lt;ul&gt; &lt;% @contact.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="field"&gt; &lt;%= f.label :name %&gt;&lt;br /&gt; &lt;%= f.text_field :name %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :position %&gt;&lt;br /&gt; &lt;%= f.text_field :position %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :email %&gt;&lt;br /&gt; &lt;%= f.text_field :email %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :telephone %&gt;&lt;br /&gt; &lt;%= f.text_field :telephone %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :source %&gt;&lt;br /&gt; &lt;%= f.text_field :source %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :company_id %&gt;&lt;br /&gt; &lt;%= f.text_field :company_id %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload