title: How to access user-entered form data from the controller
body: <p>I have 2 easy-autocomplete form fields that I want to act like nested dropdowns.</p>
  <p>They each have listeners that invoke a call to the controller which in turn populates the dropdown. This is working.</p>
  <p>When the controller call for the second field is triggered, I need to know how to access the value of the first field. I would think it would be something like form.PayTo.value, or it would show up in the params hash, but I haven't been able to find it by guessing or looking online.</p>
  <p>Better yet, is there a way to dump all objects that are available in memory at the time and I can just search for what I need?</p>
  <p>Here is the controller code for the 2 user entry fields:</p>
  <pre><code>  # search code for the quickentry payto box
    def search
      q = params[:q]
      @transactions = Transaction.select(&quot;distinct PayTo&quot;).where( &quot;PayTo like ?&quot;, &quot;#{q}%&quot;)
    end
  
    # search code for the quickentry Description box
    def DescSearch
      q = params[:q]
      #@transactions = Transaction.select(&quot;distinct Description&quot;).where( &quot;PayTo = &quot; + :PayTo.to_s + &quot; and Description like ?&quot;, &quot;#{q}%&quot;)
      @transactions = Transaction.select(&quot;distinct Description&quot;).where( &quot;PayTo = ? and Description like ?&quot;, &quot;#{:PayTo}&quot;, &quot;#{q}%&quot;)
      puts params
    end
  </code></pre>
  <p>Here is what the console shows:</p>
  <pre>Started GET "/quickentry/DescSearch.json?q=g" for ::1 at 2022-06-04 10:01:23 -0700
  Processing by TransactionsController#DescSearch as JSON
    Parameters: {"q"=>"g"}
  {"q"=>"g", "controller"=>"transactions", "action"=>"DescSearch", "format"=>"json"}
    Rendering transactions/DescSearch.json.jbuilder
    Transaction Load (0.3ms)  SELECT distinct Description FROM "transactions" WHERE (PayTo = <b>'PayTo'</b> and Description like 'g%')
    ↳ app/views/transactions/DescSearch.json.jbuilder:1
    Rendered transactions/DescSearch.json.jbuilder (Duration: 1.7ms | Allocations: 713)
  Completed 200 OK in 3ms (Views: 2.1ms | ActiveRecord: 0.3ms | Allocations: 1304)</pre>
  <p>The query is using the literal 'PayTo' instead of the value from the PayTo field.</p>
  <p>Here is quickentry.html.erb</p>
  <pre><code>&lt;h1&gt;Quick transaction entry form&lt;/h1&gt;
  &lt;%= render 'quickentryform', transaction: @transaction %&gt;
  &lt;%= link_to 'Back', transactions_path %&gt;
  </code></pre>
  <p>And here is quickentryform.html.erb (with some irrelevant fields snipped out)</p>
  <pre><code>&lt;%= form_with(model: transaction) do |form| %&gt;
    &lt;% if transaction.errors.any? %&gt;
      &lt;div id=&quot;error_explanation&quot;&gt;
        &lt;h2&gt;&lt;%= pluralize(transaction.errors.count, &quot;error&quot;) %&gt; prohibited this transaction from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
          &lt;% transaction.errors.each do |error| %&gt;
            &lt;li&gt;&lt;%= error.full_message %&gt;&lt;/li&gt;
          &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div class=&quot;field&quot;&gt;
      &lt;%= form.label :PayTo %&gt;
      &lt;%= form.search_field :PayTo, placeholder:&quot;Enter name...&quot;, &quot;data-behavior&quot;:&quot;autocomplete&quot;, name:&quot;PayTo&quot;  %&gt;
    &lt;/div&gt;
  
    &lt;div class=&quot;field&quot;&gt;
      &lt;%= form.label :Description %&gt;
      &lt;%= form.search_field :Description, placeholder:&quot;Enter Description...&quot;, name:&quot;Description&quot; %&gt;
    &lt;/div&gt;
  
    &lt;div class=&quot;field&quot;&gt;
      &lt;%= form.label :Notes %&gt;
      &lt;%= form.text_field :Notes %&gt;
    &lt;/div&gt;
  
    &lt;div class=&quot;actions&quot;&gt;
      &lt;%= form.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/eK8ZV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eK8ZV.png" alt="Entry in Payto field" /></a></p>
  <p><a href="https://i.stack.imgur.com/cEKnH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cEKnH.png" alt="Entry in Description field" /></a></p>