Skip to content

Instantly share code, notes, and snippets.

@oojikoo-gist
oojikoo-gist / Polymorphic_with_devise_2.md
Created April 17, 2015 13:51
rails: Polymorphic Associations in Rails4, Part2
@oojikoo-gist
oojikoo-gist / rspec3_config.md
Created April 17, 2015 20:25
rails: rspec3

Rails 4 with Rspec 3

Configure your Gemfile

# Gemfile
group :development, :test do
  gem 'rspec-rails', '~> 3.0.0'
  gem 'factory_girl_rails'
  gem 'capybara'
@oojikoo-gist
oojikoo-gist / alternative_polymorphic.md
Created April 20, 2015 13:34
rails: polymorphic model alternative

Alternative polymorphic model

Here's a fully working example:

# The migration file:
class CreateUserEntities < ActiveRecord::Migration
  def change
    create_table :user_entities do |t|
      t.integer :user_id
@oojikoo-gist
oojikoo-gist / rails_dictionary.rb
Last active August 29, 2015 14:19
rails: methods dictionary
# rails methods
# returns column_names arrays
Model.column_names
# returns attr_keys arrays
object.attributes.keys
# returns attr_keys values
object.attributes.values
@oojikoo-gist
oojikoo-gist / migration_dictionary.rb
Created April 20, 2015 18:01
rails: migration dictionary
# rails migration
########################
# add column to exsting table
########################
def up
add_column :users, :status, :string
User.find_each do |user|
user.status = 'active'
@oojikoo-gist
oojikoo-gist / meta_programming_dictionary.rb
Last active August 29, 2015 14:19
rails: meta programming dictionary
# ref: http://www.jimmycuadra.com/posts/metaprogramming-ruby-class-eval-and-instance-eval)
class Person
end
Person.class_eval do
def say_hello
"Hello!"
end
end
@oojikoo-gist
oojikoo-gist / generator_dictionary.md
Last active August 29, 2015 14:19
rails: generator dictionary

rails generator dictionary

basic

$ rails g model user email age:integer
  • data_type
    • integer
    • primary_key
@oojikoo-gist
oojikoo-gist / polymorphic_module.rb
Last active August 29, 2015 14:19
rails: polymorphic module
##########################################################
# polymorphic as module
##########################################################
# app/models/comment.rb
#
class Comment < ActiveRecord::Base
belongs_to :commenter, :polymorphic => true
end
@oojikoo-gist
oojikoo-gist / css_dictionary.css
Created April 24, 2015 16:19
rails: css_dictionary.css
// CSS dictionary
// <a href="#" rel="friend nofollow">Larry</a>
li a[rel~='friend'] {
font-weight: bold;
}
// target only #upperSection, #lowerSection
// <div id="upperSection">
// <p>Lorem ipsum dolor sit amet...</p>
@oojikoo-gist
oojikoo-gist / install_postgis_ubuntu.sh
Created July 28, 2015 06:31
ubuntu: install_postgis
# 나는 이녀석을 참고했다.
# http://linfiniti.com/2012/05/installing-postgis-2-0-on-ubuntu/
#
# 환경변수에 LC_COLLATE=C 이거 있는지 확인
#1. Install PostgreSQL postgis and postgres
sudo dpkg --purge postgis postgresql-9.1-postgis
sudo apt-get install python-software-properties