GavinBelson
GavinBelson

Reputation: 2784

Getting a form get parameter

I am having trouble reading the business_id parameter from a form get request.

http://localhost:3000/clients?utf8=%E2%9C%93&client%5Bbusiness_id%5D=toyota&commit=Save+Client

With: params[:business_id]

Why doesn't that work?

Details:

html form:

<%= form_for :client, url:clients_path, method: :get do |f| %>
    <%= f.label :business_id %><br>
    <%= f.text_field :business_id %>
   <%= f.submit%>
<% end %>

The form hits the create controller and redirects back to the original page:

def create
    @clients = Client.all
    redirect_to controller: 'clients'
end

On the original page reads the url string in the index controller with:

def index
    @clients = Client.all
    @filters = params[:business_id]
end

@filters comes back as blank unless I hard code a value.

Upvotes: 0

Views: 49

Answers (1)

Pavan
Pavan

Reputation: 33542

You need to use params[:client][:business_id] as business_id is inside client hash.

Upvotes: 0

Related Questions