Question: I am trying to build a website using Ruby on Rails that presents a question to the user(say on page1). After the user submits an answer to the question he goes to page2. I want to record his response, check with my database for its correctness and I want to give a feedback and also present the next question on the same page(page2).

I want to conceptually understand how can I do the above. When do I use HTTP GET and POST?

Answer: 
**Data Persistence**

> 
> I want to record his response, check with my database for its
>  correctness and I want to give a feedback and also present the next
>  question on the same page(page2)
> 
> 
> 

This will likely be achieved using a [`session based model`](http://railscasts.com/episodes/119-session-based-model) - whereby the question response is created sequentially:

```
#app/models/form_response.rb
class FormResponse
  def initialize(session)
    @session = session
    @session[:form_response] ||= []
  end

  def process_response(response)
    #response here
  end

  ...
end

```

This will allow you to store the response, and evaluate over time. There's a great [Railscast](http://railscasts.com/episodes/119-session-based-model) about it here:

![enter image description here](https://i.stack.imgur.com/e69Ac.png)

In terms of the `POST` / `GET` requests, I'd be tempted to use `POST`, as this will keep your application modular (the params are not stored in the URL etc)

The way to do this would be as follows:

```
#config/routes.rb
resources :controller do
   collection do
      post :page1
      post :page2
      post :summary
   end
end

#app/controllers/your_controller.rb
Class YourController < ApplicationController
    def page1 
        @form = FormResponse.new(session)
        render :page2
    end
end

```

--

**Ajax**

You'll may also want to use [`ajax`](http://en.wikipedia.org/wiki/Ajax_(programming)) for this

Ajax is the ability to send an **asynchronous** request to your application, through JS. In fact, Ajax actually stands for `Aysnchronous Javascript and XML`, which means you need to be able to use it to send a *hidden* request to your controller, processing the response as you require

You'll want to use this for UX more than anything (the ability for a user to stay on the same page to edit their response). I can detail more about this if you wanted
This sounds more like a general question about HTTP than Ruby on Rails so I'll approach it that way. At a high level the HTTP exchange will look something like this:

1. The user/browser sends an HTTP request to your server and waits for a response. This can be, for example, a GET or POST request.
2. Your server will process that request (eg. using Rails in your case) and send an HTTP response back to the user. The response will contain a status code and an optional body.
3. The user/browser receives the response and processes it. The response body often is the HTML markup of a web page, in which case, it will be rendered in the browser. The page may contain links or forms that the user can click on or submit, which then brings us back up to Step 1.

I'd suggest you read more about the HTTP protocol (eg. on [Wikipedia](http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Example_session))