Question: I have a form\_for, which has an input text field, the inputed text is sent to a controller which is doing a search on a table from db.

But I would like to do something different, instead of inputing the text in a text field, I want to create default search queries. Which will be buttons with text, and based on that text a param will be sent to the controller and do the search.

How can I do this? I am using Rails 4

My form\_tag

```
<%= form_tag pos_project(@project), method: :get do %>
<p>
 <%= text_field_tag :query, params[:query] %>
 <%= submit_tag "Search", name: nil %>
</p>
<% end %>

```

What I want to achieve:

Button:(text in the button) -> MyButton
When clicked on this button, the text `MyButton` will be sent to the controller, the controller will take the param, and query the db table and display the results which contain the text MyButton using the below query.

`where("name @@ :q", q: query)`

Answer: 
Why not use HTML and Javascript:

```
<!-- in your view -->
<%= form_tag pos_project(@project), method: :get, id: "your_search_form" do %>
<p>
 <%= hidden_field_tag :query, params[:query] %>
 <%= submit_tag "Search", name: nil %>
</p>

<% for value in your_preset_values do %>
  <%= link_to(value, '#', data: { search_query_value: value }, class: "search-query-link")
<% end %>

```

And in your coffee.js file:

```
# A class for the Search form JS
class SearchForm

  constructor: ->
    # when a search query link is clicked...
    $('a.search-query-link').click (e) ->
      # find the value from the data attribute
      searchQuery = $(this).data('search-query-value')
      # assign the value to the hidden field
      $("input[type='hidden']#query").val(searchQuery)
      # optional - submit the form
      $("#your_search_form")[0].submit()

# Called when the document is loaded    
jQuery ->
  new SearchForm()

```
You can use "commit" from parameter to find which button is pressed.

So in controller you will get

```
params[:commit]="button1" # or
params[:commit]="button2" # or 
params[:commit]="button3" # based on which button you pressed

```