Skip to content

Instantly share code, notes, and snippets.

View codespore's full-sized avatar
🔍
Looking for my next mission

Adrian Teh codespore

🔍
Looking for my next mission
View GitHub Profile
@codespore
codespore / rspec_rails_setup.rb
Last active April 29, 2020 21:49
Guide to setup RSpec 4 in your Rails 6 application
# Spin up a new rails application and make sure your database and schema is created
rails new example-app -T -d postgresql
# Add and install the following gems to your Gemfile
group :development, :test do
...
gem 'rspec-rails'
gem 'capybara'
gem 'selenium-webdriver'
end
@codespore
codespore / gist:14254268e2a87843d48a722b75f4a248
Created September 8, 2019 02:49 — forked from dirkgroenen/gist:07c3e8e4bc7e08bc3232ae0bdd6a0ba5
Backup Heroku Postgres database and restore to local database

Grab new backup of database

Command: heroku pgbackups:capture --remote production

Response: >>> HEROKU_POSTGRESQL_COLOR_URL (DATABASE_URL) ----backup---> a712

Get url of backup download

Command: heroku pgbackups:url [db_key] --remote production

@codespore
codespore / ruby_on_rails_deployment.md
Created August 23, 2019 17:37 — forked from zentetsukenz/ruby_on_rails_deployment.md
Deploy Ruby on Rails application with Docker Compose and Capistrano with ease

#Docker

##Files and Folders.

|
|\_ app
|...
|\_ docker
| |
@codespore
codespore / success_failure_blocks.rb
Last active May 9, 2020 01:39
How to refactor controller actions using success or failure block
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def create
@post = Post.new(post_params)
CreatePost.call(@post) do |success, failure|
success.call { redirect_to posts_path, notice: 'Successfully created post.' }
failure.call { render :new }
end
end
end
// app/assets/stylesheets/home.css
h1 { color: green; }
// app/javascript/stylesheets/application.scss
@import "~bootstrap/scss/bootstrap"; // never forget the semicolon
@import "./_custom";
@import "stylesheets/home";
{
"name": "helloworld",
"private": true,
"dependencies": {
"@rails/actioncable": "^6.0.0-alpha",
"@rails/activestorage": "^6.0.0-alpha",
"@rails/ujs": "^6.0.0-alpha",
"@rails/webpacker": "^4.0.7",
"bootstrap": "^4.3.1",
"jquery": "^3.4.1",
# config/routes.rb
Rails.application.routes.draw do
get '/calendar', to: 'calendar#index'
root to: 'home#index'
end
# app/javascript/packs/calendar.js
alert('Calendar loaded')
# app/controllers/calendar_controller.rb
# app/javascript/packs/stylesheets/application.scss
@import "~bootstrap/scss/bootstrap"; // never forget the semicolon at the end
@import "./_custom";
# app/javascript/packs/stylesheets/_custom.scss
h1 {
color: red;
}
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
import 'bootstrap'
document.addEventListener("turbolinks:load", () => {
$('[data-toggle="tooltip"]').tooltip()
})
const { environment } = require('@rails/webpacker')
const webpack = require('webpack')
environment.plugins.append('Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
})
)