0

What I want to do is pass a the value of the fields in the form to the controller so I can make a custom query in the db. I think something is missing but I just can't see what.

This is my controller

 def index

    @contributions = Contribution.all
    @number1 = params[:number1]
    @number2 = params[:number2]
    @itemsok = Contribution.where("first_item_id = ?",@numer1).where("first_item_grade = ?",@numer2) 


    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @contributions }
    end

This is the view

<%= form_tag(contribution_path, :method => "get") do %>
  <%= label_tag(:number1, "Number 1:") %>
  <%= text_field_tag(:number1) %>
  <%= label_tag(:number1, "Number 2:") %>
  <%= text_field_tag(:number2) %>
  <%= submit_tag("Searcs") %>
<% end %>

And this is the line in the routes.rb

  get 'contribution' => 'contributions#index', :as => 'contribution'   

Thank you very much.

1
  • Looks like a typo in controller. You're assigning @numberX vars but using @numerX in query. Commented Jan 2, 2012 at 12:44

1 Answer 1

1

Add :remote => true to the form tag to make it submit via ajax, and make sure to respond_to format.js in the controller action.

<%= form_tag(contribution_path, :remote => true) %>
Sign up to request clarification or add additional context in comments.

Comments

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.