How It Works Features Pricing Blog Error Guides
Log In Start Free Trial
Rails · Ruby

Fix ActionController::UnknownFormat: ActionController::UnknownFormat: TurboStreamController#create is missing a template for this request format and target in Rails

This error occurs when a controller action receives a Turbo Stream request but has no corresponding turbo_stream template or respond_to block handling the format. Create a .turbo_stream.erb template or add format.turbo_stream to your respond_to block to handle Turbo Stream requests properly in your Rails controller.

Reading the Stack Trace

ActionController::UnknownFormat (CommentsController#create is missing a template for this request format): actionpack (7.1.3) lib/action_controller/metal/implicit_render.rb:43:in `default_render' actionpack (7.1.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action' actionpack (7.1.3) lib/abstract_controller/base.rb:224:in `process_action' app/controllers/comments_controller.rb:10:in `create' turbo-rails (1.5.0) lib/turbo/broadcastable.rb:130:in `broadcast_action'

Here's what each line means:

Common Causes

1. Missing turbo_stream template

The controller action has no .turbo_stream.erb template file for the action.

# app/controllers/comments_controller.rb
def create
  @comment = @post.comments.create!(comment_params)
  # No app/views/comments/create.turbo_stream.erb exists
end

2. Missing respond_to block

The controller does not have a respond_to block that handles the turbo_stream format.

def create
  @comment = @post.comments.create!(comment_params)
  redirect_to @post  # Only handles HTML, not turbo_stream
end

3. Turbo Drive submitting as turbo_stream

A form with data-turbo=true submits as turbo_stream format but the controller only handles HTML.

<%= form_with model: [@post, Comment.new] do |f| %>
  <%= f.text_area :body %>
  <%= f.submit 'Add Comment' %>
<% end %>
<!-- Turbo submits this as turbo_stream by default -->

The Fix

Add a respond_to block that handles both turbo_stream and HTML formats. Create a .turbo_stream.erb template that uses turbo_stream helpers to update the page. The HTML fallback handles non-Turbo requests.

Before (broken)
def create
  @comment = @post.comments.create!(comment_params)
  redirect_to @post
end
After (fixed)
def create
  @comment = @post.comments.create!(comment_params)

  respond_to do |format|
    format.turbo_stream
    format.html { redirect_to @post }
  end
end

# app/views/comments/create.turbo_stream.erb
# <%= turbo_stream.append 'comments', partial: 'comments/comment', locals: { comment: @comment } %>

Testing the Fix

require 'rails_helper'

RSpec.describe CommentsController, type: :request do
  let(:post_record) { create(:post) }

  describe 'POST /posts/:post_id/comments' do
    it 'responds to turbo_stream format' do
      post post_comments_path(post_record),
           params: { comment: { body: 'Great post!' } },
           headers: { 'Accept' => 'text/vnd.turbo-stream.html' }
      expect(response).to have_http_status(:ok)
      expect(response.media_type).to eq('text/vnd.turbo-stream.html')
    end

    it 'falls back to HTML redirect' do
      post post_comments_path(post_record),
           params: { comment: { body: 'Great post!' } }
      expect(response).to redirect_to(post_record)
    end
  end
end

Run your tests:

bundle exec rspec spec/requests/comments_spec.rb

Pushing Through CI/CD

git checkout -b fix/rails-turbo-stream-format,git add app/controllers/comments_controller.rb app/views/comments/create.turbo_stream.erb,git commit -m "fix: handle turbo_stream format in comments controller",git push origin fix/rails-turbo-stream-format

Your CI config should look something like this:

name: CI
on:
  pull_request:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:16
        env:
          POSTGRES_PASSWORD: postgres
        ports: ['5432:5432']
    steps:
      - uses: actions/checkout@v4
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: '3.3'
          bundler-cache: true
      - run: bin/rails db:setup
      - run: bundle exec rspec

The Full Manual Process: 18 Steps

Here's every step you just went through to fix this one bug:

  1. Notice the error alert or see it in your monitoring tool
  2. Open the error dashboard and read the stack trace
  3. Identify the file and line number from the stack trace
  4. Open your IDE and navigate to the file
  5. Read the surrounding code to understand context
  6. Reproduce the error locally
  7. Identify the root cause
  8. Write the fix
  9. Run the test suite locally
  10. Fix any failing tests
  11. Write new tests covering the edge case
  12. Run the full test suite again
  13. Create a new git branch
  14. Commit and push your changes
  15. Open a pull request
  16. Wait for code review
  17. Merge and deploy to production
  18. Monitor production to confirm the error is resolved

Total time: 30-60 minutes. For one bug.

Or Let bugstack Fix It in Under 2 minutes

Every step above? bugstack does it automatically.

Step 1: Install the SDK

gem install bugstack

Step 2: Initialize

require 'bugstack'

Bugstack.init(api_key: ENV['BUGSTACK_API_KEY'])

Step 3: There is no step 3.

bugstack handles everything from here:

  1. Captures the stack trace and request context
  2. Pulls the relevant source files from your GitHub repo
  3. Analyzes the error and understands the code context
  4. Generates a minimal, verified fix
  5. Runs your existing test suite
  6. Pushes through your CI/CD pipeline
  7. Deploys to production (or opens a PR for review)

Time from error to fix deployed: Under 2 minutes.

Human involvement: zero.

Try bugstack Free →

No credit card. 5-minute setup. Cancel anytime.

Deploying the Fix (Manual Path)

  1. Create turbo_stream templates for all relevant actions.
  2. Add respond_to blocks in controllers.
  3. Test with and without Turbo enabled.
  4. Open a pull request.
  5. Merge and verify Turbo Stream updates work in staging.

Frequently Asked Questions

BugStack runs the fix through your existing test suite, generates additional edge-case tests, and validates that no other components are affected before marking it safe to deploy.

BugStack never pushes directly to production. Every fix goes through a pull request with full CI checks, so your team can review it before merging.

Yes, add data-turbo='false' to the form element. This makes it submit as a regular HTML form without Turbo Stream.

Turbo Frames replace content within a frame element. Turbo Streams can append, prepend, replace, or remove content anywhere on the page using target IDs.