Question: I have the following line of code, which conditionally redirects that I would like to include in my Rails controller and execute only in the case that the request is an HTML request.

I would like to skip this logic in the case that the request is JSON. How does one do this in conjunction with the `respond_to :html, :json` method, declared before all controller actions?

```
redirect_to some_controller and return if @pages.empty?

```

Answer: 
You want something like this:

```
class SomeController < ApplicationController
  def index
    @pages = Pages.find(:all)

    respond_to do |format|
      format.html do
        redirect_to other_controller and return if @pages.empty
        # ... other logic ...
      end
      format.json { render json: @pages }
    end
  end
end

```
You mean just branch logic by HTTP request format. 

```
respond_to do |format|
  format.html {your_html_logic }
  format.json { your_json_logic  }
end

```