
Ruby Rails Application
A solo builder uses Ruby on Rails to rapidly build scalable backend APIs and web applications with built-in database ORM, authentication, and routing.
Install
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill ruby-rails-applicationWhat is this skill?
- Active Record queries for efficient database operations
- JWT authentication with token encoding/decoding
- Service-oriented architecture for clean business logic
Adoption & trust: 539 installs on skills.sh; 250 GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Journey fit
Rails is essential during the build phase when constructing the core backend logic and APIs that power your application. This covers backend development patterns including Active Record queries for data operations, JWT authentication for secure access control, and service architecture for organizing business logic.
Common Questions / FAQ
Is Ruby Rails Application safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Ruby Rails Application
# Active Record Queries ## Active Record Queries ```ruby # app/services/post_service.rb class PostService def self.get_user_posts(user_id, status: nil) posts = Post.by_author(user_id) posts = posts.where(status: status) if status.present? posts.recent end def self.trending_posts(limit: 10) Post.published .joins(:comments) .group('posts.id') .order('COUNT(comments.id) DESC') .limit(limit) end def self.search_posts(query) Post.published .where("title ILIKE ? OR content ILIKE ?", "%#{query}%", "%#{query}%") .recent end def self.archive_old_drafts(days: 30) Post.where(status: :draft) .where('created_at < ?', days.days.ago) .update_all(status: :archived) end end # Usage posts = Post.includes(:user).recent.limit(10) recent_comments = Comment.where(post_id: post.id).order(created_at: :desc).limit(5) ``` # Authentication with JWT ## Authentication with JWT ```ruby # app/controllers/application_controller.rb class ApplicationController < ActionController::API include ActionController::Cookies SECRET_KEY = Rails.application.secrets.secret_key_base def encode_token(user_id) payload = { user_id: user_id, exp: 24.hours.from_now.to_i } JWT.encode(payload, SECRET_KEY, 'HS256') end def decode_token(token) begin JWT.decode(token, SECRET_KEY, true, { algorithm: 'HS256' }) rescue JWT::ExpiredSignature, JWT::DecodeError nil end end def authenticate_request header = request.headers['Authorization'] token = header.split(' ').last if header.present? decoded = decode_token(token) if decoded @current_user_id = decoded[0]['user_id'] @current_user = User.find(@current_user_id) else render json: { error: 'Unauthorized' }, status: :unauthorized end end def current_user @current_user end def logged_in? current_user.present? end end # config/routes.rb Rails.application.routes.draw do namespace :api do namespace :v1 do post 'auth/login', to: 'auth#login' post 'auth/register', to: 'auth#register' resources :users resources :posts do member do patch :publish end resources :comments, only: [:index, :create, :destroy] end end end end ``` # Controllers with RESTful Actions ## Controllers with RESTful Actions ```ruby # app/controllers/api/v1/users_controller.rb module Api module V1 class UsersController < ApplicationController before_action :authenticate_request, except: [:create] before_action :set_user, only: [:show, :update, :destroy] before_action :authorize_user!, only: [:update, :destroy] def index users = User.all users = users.where("email ILIKE ?", "%#{params[:q]}%") if params[:q].present? users = users.page(params[:page]).per(params[:limit] || 20) render json: { data: users, pagination: pagination_data(users) } end def show render json: @user end def create user = User.new(user_params) if user.save token = encode_token(user.id) render json: { user: user, token: token }, status: :created else render json: { errors: user.errors.full_messages }, status: :unprocessable_entity end end def update if @user.update(user_params) render json: @user else render json: { errors: @user.errors.full_messages }, status: :unprocessable_entity end end def destroy @user.destroy head :no_content end private def set_user @user = User.find(params[:id]) rescue ActiveRecord::RecordNotFound render json: { error: 'User not found' }, status: :not_found end def authorize_user! unless current_user.id == @user.id || c