title: What method could I use to send a form text_field to my Rails controller?
body: <p>I have two fields shown below that look like this on my website:</p>
  
  <p><a href="https://i.stack.imgur.com/IiMIG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IiMIG.png" alt="enter image description here"></a></p>
  
  <p>What I am trying to do is to implement an autocomplete function for the textfields. Now the Project Name text field works just fine but for my ticket I need to fix the broken Committer Name field which currently does not have the autocomplete feature. </p>
  
  <p>The trick that I am facing is that it would seem that the Committer Name text_field is contingent upon whether the field in Project Name is entered or not. For example, by taking a look at the code, the Committer Name won't be able to execute autocomplete unless the Project Name has a project to look for. Here is the code for the view and controller.</p>
  
  <pre><code>%fieldset.row-fluid
  
  
  .form-group
      %label.control-label.required= t('.project_name')
      .controls
        - value = params[:position].present? ? params[:position][:project_oss] : position.try(:project).try(:name)
        = f.text_field :project_oss, class: 'col-md-4 autocompletable', value: value,
        data: { source: '/autocompletes/project' }
        - error_tag(position, :project_oss)
        %p.help-block= t('.enter_openhub_project_name')
  
    .form-group
      %label.control-label= t('.committer_name')
      .controls
        = f.text_field :committer_name, class: 'col-md-4 autocompletable',
        data: { source: '/autocompletes/contributions' }
        - error_tag(position, :committer_name)
        %p.help-block
          = t('.enter_scm_committer_id')
          %br
          = t('.leave_this_blank')
  </code></pre>
  
  <p>Here is the controller code:</p>
  
  <pre><code> class AutocompletesController &lt; ApplicationController
    before_action :check_for_project, only: :contributions
    before_action :set_name_facts, only: :contributions
  
    def account
      accounts = params[:term].blank? ? [] : Account.simple_search(params[:term])
      render json: accounts.map { |a| { login: a.login, name: a.name, value: a.login, id: a.id } }
    end
  
    def project
      @projects = Project.not_deleted
                  .where('lower(name) like ?', "%#{ (params[:term] || '').downcase }%")
                  .where.not(id: params[:exclude_project_id].to_i)
                  .order('length(name)')
                  .limit(25)
    end
  
    def licenses
      licenses = params[:term] ? License.autocomplete(params[:term]) : []
      render text: licenses.map { |l| { nice_name: l.nice_name, id: l.id.to_s } }.to_json
    end
  
    def contributions
      render json: @name_facts.map { |nf| nf.name.name }
    end
  
    def tags
      tags = Tag.select(:name).autocomplete(params[:project_id], params[:term]).limit(10).map(&amp;:name)
      render json: tags
    end
  
    private
  
    def set_name_facts
      @name_facts = NameFact.where(analysis_id: @project.best_analysis_id)
                    .where(['lower(names.name) like ? ', "%#{params[:term].strip.downcase}%"])
                    .includes(:name).references(:all).order('names.name ASC').limit(10)
    end
  
    def check_for_project
      project_name = params[:project].to_s.strip.downcase
      @project = Project.active.where(['lower(name) = ?', project_name]).first unless project_name.empty?
      render text: '' if @project.nil? || @project.best_analysis_id.nil?
    end
  end
  </code></pre>
  
  <p>The problem is the before_action <code>:check_for_project</code>. In order for this to work, the <code>params[:project]</code> needs to be entered. However, it's always empty so the <code>render text:</code> portion is always implemented.</p>
  
  <p>So here is what I need. Once a user enters a Project Name onto the first text_field, how can I capture that and that value and pass it in as <code>params[:project]</code> I know how to pass Rails controller variables to javascript but not the reverse. Does anyone have any ideas. Should I submit it automatically? That seems kind of complicated.</p>