Send email asynchroniously using Sidekiq.
Create your mailer us usual:
# Variant 1 | |
def user_params(type) | |
params.require(type.to_sym).permit(attributes) | |
end | |
# Variant 2 | |
def user_params(type) | |
case type | |
when "user" | |
params.require(:user).permit(user_attributes) |
class Comment < ActiveRecord::Base | |
belongs_to :post, counter_cache: true | |
end |
# Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. | |
# e.g. [[1,2,[3]],4] -> [1,2,3,4]. | |
# SOLUTION | |
class Array | |
def flatten_array(number = nil) | |
number ? multiple_flatten(self, number) : recursive_flatten(self) | |
end |
## When Should I Not Use a Service Object? | |
This one’s easy. I have these rules: | |
1. Does your code handle routing, params or do other controller-y things? | |
If so, don’t use a service object—your code belongs in the controller. | |
2. Are you trying to share your code in different controllers? | |
In this case, don’t use a service object—use a concern. | |
3. Is your code like a model that doesn’t need persistence? |
FROM ruby:2.4 | |
## In case of postgresql for heroku: | |
# RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" >> /etc/apt/sources.list.d/postgeresql.list \ | |
# && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ | |
# && apt-get update \ | |
# && apt-get update \ | |
# && apt-get install -y --no-install-recommends \ | |
# postgresql-client-9.6 pv ack-grep ccze unp htop vim \ | |
# && rm -rf /var/lib/apt/lists/* \ |
------------ From Rake Task | |
namespace :app do | |
# Checks and ensures task is not run in production. | |
task :ensure_development_environment => :environment do | |
if Rails.env.production? | |
raise "\nI'm sorry, I can't do that.\n(You're asking me to drop your production database.)" | |
end | |
end |
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.
# coding: utf-8 | |
import json | |
import stripe | |
import datetime | |
# Required for OAuth flow | |
from rauth import OAuth2Service | |
# Our secret key from stripe | |
STRIPE_SECRET_KEY = 'sk_test_xxxxxxxxxxxxx' |