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 / Active_Admin_Cheats.rb
Last active August 30, 2022 14:17
Quick reference to useful ActiveAdmin customizations
# Add Action button on the top navigation menu. Useful for resource with nested resources
action_item :only => :show do
link_to('Show Users', admin_group_users_path(resource))
end
# Custom show page with children items
show do
const { environment } = require('@rails/webpacker')
const webpack = require('webpack')
environment.plugins.append('Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
})
)
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
import 'bootstrap'
document.addEventListener("turbolinks:load", () => {
$('[data-toggle="tooltip"]').tooltip()
})
@codespore
codespore / gist:7014ebf319db3ded52bad62185f7de56
Created August 22, 2016 00:48 — forked from arjunvenkat/gist:1115bc41bf395a162084
Seeding a Rails database with a CSV file

How to seed a Rails database with a CSV file

1. Setup

First, Create a folder inside of lib called seeds

Put your CSV file example.csv into the lib/seeds folder. In the example below, the file is called real_estate_transactions.csv

Make sure you've created a resource with the appropriate columns to match your seed data. The names don't have to match up.

@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
@codespore
codespore / boost_template.rb
Last active May 5, 2020 03:45
Rails application template
# Rails 4 Application Template
# Usage: rails new [app_name] -m [boost_template.rb] -d postgresql
# Remove normal files we don't want
remove_file "README.rdoc"
remove_file "public/index.html"
remove_file "app/assets/images/rails.png"
# Copy database.yml to sample
inside "config" do
@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

// 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";