0

i have this form :

<h1> Global data management </h1> </br> </br>
<h2>Enter the conditions and click "find" option to search for users based on conditions. </br> Or click the "List" option to list all the data.  </h2>
</br></br></br>
<%= form_for(:find_field, url: find_field_path , method: :get) do |f| %>
<div class="row">
      <div class="span8 offset1">
        <div class = "row">
            <div class = "span4">
              <div class="field">
              <%= f.label :data_type_choice, "Data type" %> 
              <%= f.select :data_type_choice, [["all","all"],["2D","2D"],["3D","3D"],["2D3C","2D3C"],["3D3C","3D3C"]] , :name => nil%>
              </div>
              </br></br>
              <h3> COMPLETED WITHIN </h3>:</br>
              <div class="field">
                <%= f.label :from_date_choice , "From date " %>
                <%= f.date_select :from_date_choice , :name => nil%>
              </div>          
            </div>

            <div class = "span4">     
              <div class="field">
              <%= f.label :basin_choice, "Basin" %>
              <%= f.select :basin_choice, [["all","all"],["Cauvery","Cauvery"],["KG-PG","KG-PG"],["others","others"]] , :name => nil %>
              </div>      
              </br></br>
              <h3>&nbsp</h3>
              <div class="field">
                <%= f.label :to_date_choice , "To date " %>
                <%= f.date_select :to_date_choice , :name => nil %>
              </div>
            </div>
        </div>    

                </br></br>
              <%= f.submit "  Search  ", class: "btn btn-large btn-primary" %>

      </div>
</div>
<% end %>

everything works perfectly, all the parameters are passed correctly etc, but in the view where im trying to display the result, i get a HUGE url like so:

http://localhost:3000/global/data/find?utf8=%E2%9C%93&find_field%5Bdata_type_choice%5D=2D&find_field%5Bfrom_date_choice%281i%29%5D=2012&find_field%5Bfrom_date_choice%282i%29%5D=7&find_field%5Bfrom_date_choice%283i%29%5D=9&find_field%5Bbasin_choice%5D=KG-PG&find_field%5Bto_date_choice%281i%29%5D=2012&find_field%5Bto_date_choice%282i%29%5D=7&find_field%5Bto_date_choice%283i%29%5D=9&commit=++Search++

ive tried using the ":name => nil" as shown in this railscast why is this happening and how can i reduce the url size to just "http://localhost:3000/global/data/find" ?

EDIT:

this is my find method in fields_controller:

  def find

    @data_type_choice = params[:find_field][:data_type_choice]
    @basin_choice = params[:find_field][:basin_choice]
    @from_date_choice = params[:find_field][:from_date_choice]
    @to_date_choice = params[:find_field][:to_date_choice]

  end

i also want to display the data entered in the form through find.html.erb like so:

<h1><%= @data_type_choice %> dsfgdfsg</h1>

if i make it a post request, the erb is not being rendered! what can i do?

thanks :)

1 Answer 1

2

Just change your method from GET to POST and change the routes accordingly.

Try

<%= form_for(:find_field, url: find_field_path , method: :post) do |f| %>

Your routing file should match the request as POST.

Sign up to request clarification or add additional context in comments.

3 Comments

i've edited my question, please tell me how i can handle that.
Does the function 'find' called? or Are you getting template missing error?
okay, i made it work, somehow just f.submit made it call fields#create :/. but when i removed it and added a : <%= button_to "search", find_field_path %> , everything magically worked! do u know why that happened? n thanks for the help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.