Skip to content

Instantly share code, notes, and snippets.

@MohamedBrary
Last active September 3, 2022 20:22
Show Gist options
  • Save MohamedBrary/12465abb009d5dbeadeb8cde9adb30b5 to your computer and use it in GitHub Desktop.
Save MohamedBrary/12465abb009d5dbeadeb8cde9adb30b5 to your computer and use it in GitHub Desktop.
New Rails App

Creating Rails Project

Initialization

# List available rubies, to choose which ruby to use
$ rvm list rubies

# To install new ruby use, for example version '2.4.1'
$ rvm install 2.4.1

# create and use the new RVM gemset for project "my_app"
$ rvm use --create 2.4.1@my_app

# install latest rails into the blank gemset
$ gem install rails

# Creates new rails app "my_app"
# -d mysql: defining database (other options: mysql, oracle, postgresql, sqlite3, frontbase)
# -T to skip generating test folder and files (in case of planning to use rspec)
$ rails new my_app -d mysql -T

# go into the new project directory and create a .ruby-version and .ruby-gemset for the project
$ cd my_app
$ rvm --ruby-version use 2.4.1@my_app

# initialize git
$ git init
$ git add .
$ git commit -m 'new rails app'
$ git remote add origin git@git.x.com:x/my_app.git
$ git push -u origin master

Gems

Haml and Bootstrap

gem 'haml-rails'
gem 'bootstrap-generators' # to generate views using bootstrap
$ rake haml:erb2haml
$ rails generate bootstrap:install --template-engine=haml

Devise and OmniAuth

gem 'devise', '~> 3.4'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'omniauth-instagram'
gem 'twitter'
gem 'instagram'
gem 'omniauth-google-oauth2'
gem 'google-api-client', require: 'google/api_client'
gem 'devise-bootstrap-views' # to generate bootstrap devise views
$ rails g devise:views:bootstrap_haml_templates
$ rails g scaffold User name role:integer
$ rails generate devise User

# Edit database.yml to match your configuration
$ rake db:create db:migrate

For devise and other authentication options checkout this link.

Testing

  • To setup testing checkout this link.

React

gem 'react-rails'
# Generating react files
$ rails g react:install

# Generating Main Components
rails g react:component Main controller:string action:string params:object current_user:object
rails g react:component MainNavBar controller:string current_user:object

# Generating Home Components
rails g react:component Home
rails g react:component SignIn user:object
rails g react:component SignUp user:object
rails g react:component ForgotPassword user:object

# Generating Users Components
rails g react:component UsersMain controller:string action:string params:object

rails g react:component UsersIndex users:array can_delete:bool can_edit:bool can_show:bool can_create:bool
rails g react:component UsersIndexControls params:object can_create:bool
rails g react:component UsersIndexTable users:array can_delete:bool can_edit:bool can_show:bool
rails g react:component UsersIndexTableRow user:object can_delete:bool can_edit:bool can_show:bool

rails g react:component UsersShow user:object can_delete:bool can_edit:bool
rails g react:component UsersEdit user:object can_delete:bool

# Generating Profile Component
rails g react:component ProfileMain controller:string action:string user:object can_delete:bool can_edit:bool

# Generating Shared Components
rails g react:component FormErrors errors:array

Deploy to Heroku

You need first to have an account on Heroku, and Heroku command line interface installed.

# Creating new Heroku app named app-name
$ heroku create app-name

# Deploy application
$ git push heroku master

# Setting ENV variables
heroku config:set ADMIN_NAME='Admin User' ADMIN_EMAIL=admin@myapp.com ADMIN_PASSWORD=password

# Run migrations and seed
$ heroku run rake db:migrate db:seed

# To open heroku app
$ heroku open

# Useful heroku commands
$ heroku logs --tail
$ heroku run rails console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment