try
User.all.pluck(:email)
instead of
User.select(:email).map(&:email)
overwrite default attributes
def owner=(ownder)
self.previous_owner = owner
super
end
full text search using postgreSQL plain_to ts_query
create database for each user
def connect_to_user_db(name)
config = ActiveRecord::Base.configuration['development'].merge("database" => 'db/#{name}.sqlite3")
ActiveRecord:Base.establish_connection(config)
end
migrate:db:all
write file atomatically
#remove unnecessary hash [eg. remove controller and hash] params.except(:controller,:action)
reverse_merge
#inquery method for AC class
class Article extends AC:Base
STATUES = %w[Draft Published]
def method_missing(method, *args, &block)
if method =~ /\^#{STATUS.map(&:downcase).join("|")}\?\z/
status.downcase.inquiry.send(method)
else
super
end
Views options_for_select group_options_for_select
#Queue & thread
class A < AR:Base
after_create :add_stats
def add_stats
self.calss.queue << -> {calculate_stats; save}
end
require 'thread'
def self.queue; @ queue || = Queue.new ned
def self.thread
@thread ||= Thread.new do
while job = queue.pop
job.call # job.run
end
end
end
thread
end