gem 'delayed_job_active_record'
bundle install
rails generate delayed_job:active_record
rake db:migrate
gem "paperclip", "~> 4.2"
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end
| 第1列分钟1~59 | |
| 第2列小时1~23(0表示子夜) | |
| 第3列日1~31 | |
| 第4列月1~12 | |
| 第5列星期0~6(0表示星期天) | |
| 第6列要运行的命令 | |
| 下面是crontab的格式: | |
| 分 时 日 月 星期 要运行的命令 |
| namespace :chideo do | |
| namespace :votes do | |
| desc "Import votes via the existing API and import into the database" | |
| task import: :environment do | |
| Rake::Task["chideo:votes:generate_seed_file"].invoke | |
| Rake::Task["chideo:votes:import_seed_file"].invoke | |
| end | |
| desc "Generate votes seed file" |
| # Puma | |
| # ============================================================================== | |
| namespace :puma do | |
| set :puma_pid, "#{app_path}/tmp/pids/puma.pid" | |
| set :start_puma, %{ | |
| cd #{app_path} | |
| bundle exec puma --config #{app_path}/config/puma.rb --environment #{rails_env} | |
| } | |
| # Start task |
| 统计某文件夹下文件的个数 | |
| ls -l |grep "^-"|wc -l | |
| 统计某文件夹下目录的个数 | |
| ls -l |grep "^d"|wc -l | |
| 统计文件夹下文件的个数,包括子文件夹里的 | |
| ls -lR|grep "^-"|wc -l | |
| 假如在一个目录中保留最近30天的文件,30天前的文件自动删除 |
| before_save :encrypt_note | |
| def encrypt_note | |
| salt = SecureRandom.random_bytes(64) | |
| key = encrypt_key || ActiveSupport::KeyGenerator.new(ENV["SECRET_KEY"]).generate_key(salt) | |
| crypt = ActiveSupport::MessageEncryptor.new(key) | |
| %w(client_note food medicines hydration md_appointments activity mood positive_thinking positive_action listener_note).each_with_index do |att| | |
| val = if !new_record? and send("#{att}_changed?") | |
| read_attribute(att.to_sym) |
rails generate devise:install
rails rails generate devise MODEL
rake db:migrate
rails generate devise:views
rails generate devise:controllers [scope]
you need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for config/environments/development.rb:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }