Maya Patel

50 code snips · on codesnips 5 months

Rails + React specialist building modern SPAs with Rails APIs. Expert in React hooks, state management, TypeScript, and seamless Rails integration. 9+ years creating performant,...

ruby
class PostsController < ApplicationController
  def create
    @post = current_user.posts.build(post_params)

    if @post.save
      flash[:success] = 'Post was successfully created.'

Rails Flash messages for user feedback

rails flash messages
by Maya Patel 2 tabs
typescript
import { useEffect, useState, useRef } from 'react'

interface UseInViewOptions {
  threshold?: number | number[]
  rootMargin?: string
  triggerOnce?: boolean

Intersection Observer API for visibility tracking

react performance intersection-observer
by Maya Patel 2 tabs
ruby
module Posts
  class CreateService
    def initialize(author:, params:)
      @author = author
      @params = params
    end

Rails service objects for business logic

rails architecture service-objects
by Maya Patel 2 tabs
typescript
import { useReducer } from 'react'

interface FormState {
  values: Record<string, any>
  errors: Record<string, string>
  touched: Record<string, boolean>

React useReducer for complex state logic

react hooks state-management
by Maya Patel 1 tab
ruby
Rails.application.routes.draw do
  namespace :api do
    namespace :v1 do
      resources :posts do
        resources :comments, only: [:index, :create]
      end

Rails API versioning strategies

rails api versioning
by Maya Patel 3 tabs
typescript
import { useForm } from 'react-hook-form'
import { useState } from 'react'
import api from '@/services/api'

interface SignupFormData {
  email: string

React Hook Form with async validation

react forms validation
by Maya Patel 1 tab
ruby
class SlugValidator < ActiveModel::Validator
  SLUG_REGEX = /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/

  def validate(record)
    slug = record.send(options[:attribute] || :slug)

Rails validators for custom business logic

rails validations activemodel
by Maya Patel 2 tabs
ruby
Rails.application.config.middleware.insert_before 0, Rack::Cors do
  # Development CORS - allow any localhost
  allow do
    origins(
      /http:\/\/localhost:\d+/,
      /http:\/\/127\.0\.0\.1:\d+/,

CORS configuration for Rails APIs

rails cors security
by Maya Patel 1 tab
typescript
import { memo } from 'react'
import { Post } from '@/types'

interface PostListItemProps {
  post: Post
  onLike: (id: string) => void

React memo for component optimization

react performance optimization
by Maya Patel 2 tabs
ruby
Rails.application.configure do
  # Bullet configuration
  config.after_initialize do
    Bullet.enable = true
    Bullet.alert = true # Show JavaScript alert
    Bullet.bullet_logger = true # Log to bullet.log

Rails N+1 query detection with Bullet

rails performance n-1
by Maya Patel 3 tabs
typescript
import { useEffect } from 'react'

interface KeyboardHandlers {
  [key: string]: () => void
}

Keyboard navigation and focus management

react accessibility keyboard
by Maya Patel 2 tabs
ruby
FactoryBot.define do
  factory :post do
    association :author, factory: :user
    sequence(:title) { |n| "Post Title #{n}" }
    body { Faker::Lorem.paragraphs(number: 3).join("\n\n") }
    status { :draft }

Rails fixtures vs factories for test data

rails testing fixtures
by Maya Patel 2 tabs