Skip to content

Instantly share code, notes, and snippets.

View luciuschoi's full-sized avatar

Lucius Choi luciuschoi

View GitHub Profile
@luciuschoi
luciuschoi / application.css
Last active June 27, 2023 20:06
[RailsCoop] minimal stylesheet for Ruby on Rails project
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS
* files in this directory. Styles in this file should be added after the last require_* statement.
@luciuschoi
luciuschoi / Gemfile
Created March 29, 2017 14:21 — forked from adamrobbie/Gemfile
Rails Endless pagination
gem 'will_paginate'
@luciuschoi
luciuschoi / import_passed_membership.rb
Created October 5, 2016 07:57
trevari_import_passed_membership
def import_passed_membership(csv_file="trevari_passed_membership.csv")
csv_data = open(csv_file)
csv_rows = CSV.parse(csv_data.read.force_encoding("utf-8"), { headers: true,
converters: :numeric,
header_converters: :symbol })
csv_rows.each do |m|
p m
c = Club.find(m[3])
@luciuschoi
luciuschoi / show.html.erb
Created October 2, 2016 06:54
환불요청 상태 표시
<div class="iux-has-hover iu-cell cell-136">
<% if @event.refund_requested_by?(current_user) %>
<%= link_to '환불 신청하기', refund_event_path(@event) %>
<% else %>
<%= link_to '환불 신청이 완료됨', '#' %>
<% end %>
</div>
@luciuschoi
luciuschoi / schema.rb
Last active September 28, 2016 21:08
Normalization of Club Model...
# clubs 테이블을 이와 같이 중복되는 부분을 sesons 테이블로 빼내고 club_seasons 라는 join 테이블 만들면 어떨까요?
create_table "clubs", force: :cascade do |t|
t.string "name"
t.text "description"
t.string "type"
t.string "image"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "report_length_limit", default: 400
# 감사합니다...!
# 1. Club.all.select{|k| k.memberships.count < k.max_number}
# 2. club.unconfirmed_applications.map(&:user)
# 1에 해당하는 클럽들에 대해 2번을 적용한 유저정보(특히 user.phone_number)를 추출하려면 어떻게 해야 할까요?
class Club < ApplicationRecord
scope :recruiting, -> { select{ | club | club.memberships.count < club.max_number } }

Soft Delete of Table Record

###1. Migration Class for Adding Some Delete Flags

$ rails g migration add_deleted_to_purchase_requests deleted:boolean deleted_at:datetime deleted_by:references

###2. Modification of Migration Class for Adding Foreign Key

== Coffe File
ready = ->
sendFile = (file) ->
data = new FormData
data.append 'content_image[image]', file
$.ajax
data: data
type: 'POST'
url: '/api/uploads'
# 먼저 원격 우분투 서버로 접속한 후 mysql을 설치한다.
# 그리고, 아래와 같이 root계정으로 mysql에 접속한다.
```
$ mysql -u root -p
```
아래의 명령을 실행하여 데이터베이스 및 배포용 유저를 생성하고 모든 권한 부여 한다.
class User < ActiveRecord::Base
has_many :posts
has_many :shares
has_many :shared_posts, class_name: 'Post', through: :shares, source: :post
end
class Share < ActiveRecord::Base
belongs_to :user
belongs_to :post
end