0

So I'm trying to set the default search field value to the pre-existing one if it exists

<%= form_tag universities_path, :method => "get", :class => "form-search" do %>
  <%= label_tag :query, "Search by name" %>
  <%= text_field_tag :query, :input => params[:query] unless params[:query].nil? %>
  <%= text_field_tag :query if params[:query].nil? %>
  <%= label_tag :state  %>
  <%= select_tag :state, options_for_select(@states, params[:state])   %>
  <%= submit_tag "Search", :class => 'btn' %>
<% end %>

The above code outputs a hash that looks like this ({:input=>"coastal"}). When I run the x.values where x = params[:query] I get a "undefined method `values' for "coastal":String".

Running params[:query].class yields this (to the input field), btw ({:input=>String})

coloradoblue
  • 625
  • 7
  • 11

1 Answers1

0

text_field_tag expects the second parameter as the value of the field. change

<%= text_field_tag :query, :input => params[:query] unless params[:query].nil? %>
<%= text_field_tag :query if params[:query].nil? %>

to

<%= text_field_tag :query, params[:query] %>
jvnill
  • 29,479
  • 4
  • 83
  • 86