Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass parameters in params using form_tag method in rails

I am trying to pass a parameter params[:tab] => "drive" in car_path method using form_tag but it doesnt gets available in car_path params. Here is what i am trying

<%= 
form_tag(
    car_path(@user.id), 
    {
        :method => :get, 
        params[:tab] => "drive", 
        :class => "form form-horizontal"
     }
) do 
%>
like image 205
Bloomberg Avatar asked Apr 08 '14 12:04

Bloomberg


2 Answers

Use this:

<%= form_tag(car_path(@user.id, :tab => "drive"), {:method => :get, :class => "form form-horizontal"}) do %>

Pass it with the car_path as a query parameter.

UPDATE

Look at action="/visitors/198454?tab=drive", tab = drive is passed in params. Access it as params[:tab] in your controller.

like image 151
Kirti Thorat Avatar answered Oct 08 '22 20:10

Kirti Thorat


A little different idea: isn't it better to use a hidden field inside the form?

<%= hidden_field_tag :tab , "drive" %>
like image 29
JPG Avatar answered Oct 08 '22 20:10

JPG