Skip to content

Instantly share code, notes, and snippets.

View kentarofujiy's full-sized avatar
🏠
Working from home

Kentaro Fujiy kentarofujiy

🏠
Working from home
View GitHub Profile
@kentarofujiy
kentarofujiy / webpacker_rails.md
Created March 30, 2021 20:18 — forked from maxivak/webpacker_rails.md
Webpack, Yarn, Npm in Rails
@kentarofujiy
kentarofujiy / st2vim_themes.py
Created June 19, 2020 02:52 — forked from jojonas/st2vim_themes.py
Converter for Sublime Text themes to VIM themes
from __future__ import print_function
import sys
import argparse
import os.path
import textwrap
import re
from pprint import pprint
import xml.etree.ElementTree as ET
@kentarofujiy
kentarofujiy / gist:78ff1fb384c3b44f49f8d62c10142011
Created January 6, 2020 19:39 — 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.

<?php
//set up pods::find parameters to limit to 5 items
$param = array(
'limit' => 5,
);
//create pods object
$pods = pods('pod_name', $params );
//check that total values (given limit) returned is greater than zero
if ( $pods->total() > 0 ) {
# Model
class Profile < ApplicationRecord
has_one_attached :avatar
accepts_nested_attributes_for :avatar_attachment, allow_destroy: true
end
# Controller
class ProfilesController < ApplicationController
before_action :set_profile, only: [:show, :edit, :update, :destroy]