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 should use the `respond_to` block:

```
respond_to do |format|
  format.html { redirect_to some_controller }
  format.json { render json: @data }
end

```

This will redirect to `some_controller` after an HTML request, and render JSON data after a JSON request.
You mean just branch logic by HTTP request format. 

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

```