title: Rails with searching dependent value in create a new record
body: <p>Recently started to study rails and faced with the next problem:</p>
  
  <p>I have two tables Inboxes(request) and Equipments. Inboxes has many Equipments through InboxEquipment.</p>
  
  <p>Since the equipment can be many, the searching for the right is difficult. I need to add field quick <strong>search</strong> or <strong>filter</strong> values of table Equipments. I think this can be done using Ajax, but I don't know him. Something similar is described in "Episode #240 Search, Sort, Paginate with AJAX", but I don't know how to make to search has been in the create a new record</p>
  
  <p><em>My current working code:</em></p>
  
  <p><strong>../controllers/inbox_controller.rb</strong></p>
  
  <pre><code>def new
      if signed_in?
          @inbox = Inbox.new(params[:inbox])
          @partners = @inbox.partners.build(params[:partners])
          @equipments = @inbox.equipments.search(params[:search])
      end
  end
  </code></pre>
  
  <p><strong>../inboxes/new.html.erb</strong></p>
  
  <pre><code>&lt;% if signed_in? %&gt;
  &lt;%= render 'shared/inbox_form' %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>../shared/_inbox_form.html.erb</strong></p>
  
  <pre><code>&lt;%= form_for @inbox, :html =&gt; { :multipart =&gt; true } do |f| %&gt;
      &lt;div class="new_application"&gt;
  
          &lt;h2&gt;Входящая заявка&lt;/h2&gt;
  
          &lt;%= render 'shared/error_messages', object: f.object %&gt;
          &lt;div class="fields_inbox"&gt;
              &lt;h4&gt;&lt;center&gt;Контрагент:&lt;/center&gt;&lt;/h4&gt;
              &lt;%= f.select(:partner_id, options_for_select(Partner.all.collect {|x| [x.name, x.id]}, :include_blank =&gt; "Выберите контрагента")) %&gt;
  
              &lt;%= f.select(:equipment_ids, options_for_select(Equipment.all.collect { |z| [z.name, z.id] }), {}, {:multiple=&gt;true, :size =&gt; 10}) %&gt;
  
              &lt;h4&gt;&lt;center&gt;Тип заявки:&lt;/center&gt;&lt;/h4&gt;
              &lt;%=  f.select(:application_type, ["Новая","Принята","На рассмотрении","Завершена"], :include_blank =&gt; "Выберите тип зявки") %&gt;
              &lt;center&gt;
                  &lt;%= f.submit "Добавить", class: "btn btn-large btn-primary" %&gt;
                  &lt;%= link_to "Назад", :back, :class =&gt; "btn btn-large btn-primary" %&gt;    
              &lt;/center&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Add two images as works now and how to</p>
  
  <p>So now working <a href="http://s12.postimg.org/vt91ceqkd/inbox.jpg" rel="nofollow">http://s12.postimg.org/vt91ceqkd/inbox.jpg</a> <br>
  So it should work <a href="http://s22.postimg.org/z20zb8c9d/inbox_correct.jpg" rel="nofollow">http://s22.postimg.org/z20zb8c9d/inbox_correct.jpg</a></p>
  
  <p>What do I need to add to my code to make it work as I need to (Example in second image)?</p>