$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
Ruby on RailsintermediateNew

Rails API

Share

Build Rails API-only application with serializers

Works with OpenClaude

You are a Rails backend developer building RESTful API-only applications with proper serialization layers.

What to check first

  • Run rails --version to confirm Rails 6+ is installed (API-only mode is standard)
  • Verify Gemfile includes active_model_serializers gem or uses built-in render json: with serializer classes
  • Check if the Rails app was generated with rails new myapp --api flag (skips view/asset pipeline)

Steps

  1. Generate a new API-only Rails app with rails new myapp --api --database=postgresql to skip unnecessary middleware
  2. Add gem 'active_model_serializers' to Gemfile and run bundle install
  3. Generate a resource scaffold with rails generate scaffold Post title:string content:text user:references --api to create model, controller, and migration
  4. Create serializer files manually or via rails generate serializer Post in app/serializers/post_serializer.rb
  5. Define serializer attributes and associations using attributes :id, :title, :content and belongs_to :user, serializer: UserSerializer
  6. Update controller actions to render with serializers: render json: @post, serializer: PostSerializer or let Rails infer automatically
  7. Test JSON response structure with curl -H "Content-Type: application/json" http://localhost:3000/api/v1/posts
  8. Add pagination with gem 'kaminari' and render paginated results: render json: @posts, each_serializer: PostSerializer, meta: pagination_meta(@posts)

Code

# config/routes.rb
Rails.application.routes.draw do
  namespace :api do
    namespace :v1 do
      resources :posts do
        resources :comments, only: [:index, :create]
      end
      resources :users
    end
  end
end

# app/models/post.rb
class Post < ApplicationRecord
  belongs_to :user
  has_many :comments, dependent: :destroy
  validates :title, :content, presence: true
end

# app/serializers/post_serializer.rb
class PostSerializer < ActiveModel::Serializer
  attributes :id, :title, :content, :created_at, :updated_at
  belongs_to :user, serializer: UserSerializer
  has_many :comments, serializer: CommentSerializer
end

# app/serializers/user_serializer.rb
class UserSerializer < ActiveModel::Serializer
  attributes :id, :name, :email
end

# app/controllers/api/v1/posts_controller.rb
module Api
  module V1
    class PostsController < ApplicationController
      before_action :set_post, only: [:show, :update, :destroy]

      def index
        @posts = Post.all.page(params[:page]).per(10)
        render json: @posts, each_serializer: PostSerializer

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
railsapirest

Install command:

curl -o ~/.claude/skills/rails-api.md https://clskills.in/skills/rails/rails-api.md

Related Ruby on Rails Skills

Other Claude Code skills in the same category — free to download.

Want a Ruby on Rails skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.