Coder Social home page Coder Social logo

modern-rails-sample-app's Introduction

Rails Style Guide main workflow

Modern Rails Sample App

This app was developed using Ruby on Rails + Hotwire + Turbo + Stimulus. There are many areas to improve in this code, but I wanted to demonstrate how I leveraged Hotwire + Turbo Streams and Stimulus to build a real-time validation in the frontend.

I understand that there are side effects and possible issues with this exact approach, like ending up with multiple requests being sent to the server, and an excessive amount of requests can be an issue.

GitHub actions are in place with linter, builds, and specs so we can get a proper CI/CD pipeline ready for production.

Setting up a dev environment

Dependencies

  • ruby
  • postgresql
  • node

Note: Before installing all the dependencies locally, check the Services section.

Clone repo

git clone [email protected]:lelogrott/modern-rails-sample-app.git
cd modern-rails-sample-app

Install CLI tools and programs

[OS X only] Brew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Ruby + rbenv for managing versions

Also: https://stackoverflow.com/questions/10940736/rbenv-not-changing-ruby-version

# OS X.
brew install rbenv ruby-build

# Debian, Ubuntu, and derivatives.
sudo apt install rbenv

rbenv init # Follow the printed instructions
rbenv install $(cat .ruby-version)

# You may need to restart your shell before running this command.
# Verify ruby --version is properly sourcing the newly installed
# ruby from rbenv before running this command.

gem install bundler

Node.js

Find more details about installing and updating NVM @ https://github.com/nvm-sh/nvm#installing-and-updating. Check package.json for our node version, then copy that version into ~/.nvmrc.

# Install NVM by running the following command, or check NVM
# documentation to see how to install its latest version.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

You may have to add the following to the correct profile file (probably ~/.zprofile if you're on macOS Catalina or later) and restart your terminal session:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install "$(cat .nvmrc)"
nvm use
corepack enable

Setup repo

Add ssh keys to github

  1. Create an SSH Key
  2. Add it to GitHub
  3. Add identity to git
git config --global user.name "<your_full_name>"
git config --global user.email "<your_email>"

Setup database and boot Rails server

If you are running service dependencies via docker, install libpq via brew for the pg rubygem to compile successfully.

# OS X.
brew install libpq

# Debian, Ubuntu, and derivatives.
sudo apt install libpq-dev

# Intel Macs:
bundle config --local build.pg --with-opt-dir="/usr/local/opt/libpq"
# Apple Silicon Macs:
bundle config --local build.pg --with-opt-dir="/opt/homebrew/opt/libpq"

Run the following commands:

bundle install # Installs gems, including Rails
yarn install # Install JS dependencies
rbenv rehash # Make newly installed gems available from command-line

rails console # and then `exit`

# Creates DB
rails db:create

# Sets up DB, can take a while
rails db:schema:load


# start the server with nodemon
./bin/dev

Available URLs

When server is up, you should be able to access the following URL's:

Status URL

Users URL

Done!

That should do it. If you encounter any problems, ask another engineer for help and update the steps so that the next person doesn't run into the same issue ๐Ÿ˜ƒ

Potential issues

[OS X only] Command Line Tools

try running this command after you have installed xcode sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

Puma issue with tmp/pids/ folder

No such file or directory @ rb_sysopen - tmp/pids/server.pid (Errno::ENOENT)

If Puma crashes within the message above, just create the folder /tmp/pids manually and it should work.

modern-rails-sample-app's People

Contributors

lelogrott avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.