ಛఆͷςʔϒϧͷϨίʔυͷTBWFϝιο υΛҰ࣌తʹແޮʹͰ͖ΔΑ͏ʹͳͬͨ class Comment < ActiveRecord::Base belongs_to :commentable, polymorphic: true after_create -> { Notification.create! comment: self, recipients: commentable.recipients } end module Copyable def copy_to(destination) Notification.suppress do # Copy logic that creates new comments that we do not want # triggering notifications. end end end
"3ͷϞσϧͷ͏ͪɺͲͷଐੑʹΞΫη ε͍ͯ͠Δ͔ΛऔಘͰ͖ΔΑ͏ʹͳͬͨ w [email protected]ϝιου w ςʔϒϧͷશͯͷΧϥϜΛऔಘ͢ΔͷΛΊͯগ ͠ͰΛ্͍͛ͨ࣌ʹ͏ w TFMFDUͰΧϥϜΛߜΓ͍͚ͨͲɺϏϡʔ͕ෳࡶ ͰͲͷΧϥϜ͕ΘΕ͍ͯΔ͔ௐΔͷ͕໘ ͳͱ͖ʹ͑Δ
"3ͷϞσϧͷ͏ͪɺͲͷଐੑʹΞΫη ε͍ͯ͠Δ͔ΛऔಘͰ͖ΔΑ͏ʹͳͬͨ class UsersController < ApplicationController after_action :print_accessed_fields def index @users = User.all end private def print_accessed_fields p @users.first.accessed_fields end end
"3ͷϞσϧͷ͏ͪɺͲͷଐੑʹΞΫη ε͍ͯ͠Δ͔ΛऔಘͰ͖ΔΑ͏ʹͳͬͨ class UsersController < ApplicationController def index @users = User.select(:name, :email) end end Processing by UsersController#index as HTML User Load (0.1ms) SELECT "users".* FROM "users" Rendered users/index.html.erb within layouts/application (1.0ms) ["name", "email"] গ͚ͩ͠ߴԽ
IFSPLVରԠ w IFSPLVͰɺQSPEVDUJPOͷ%#ফͪ͠ΌͬͨΜ͚ͩͲͳΜͱ͔෮چͰ͖ͳ͍ʁΈ ͍ͨͳ͍߹Θ͕ͤ݁ߏ͋ΔΒ͘͠ɺͦΕΛݮΒͨ͢Ίͷमਖ਼͕ೖͬͨ w SBJMTECESPQͳͲͷ%#ഁյܥλεΫ͕QSPEVDUJPOڥͰؒҧ࣮͑ͯߦͯ͠͠· ͏ͷΛࢭ w %*4"#-&@%"5"#"4&@&/7*30/.&/[email protected]$)&$,ɹͱ͢Δͱ࣮ߦͰ͖Δ w Ұ൪࠷ޙʹ%#Λϩʔυͨ͠FOWJSPONFOUͱɺআ͢Δ%#ͷFOWJSPONFOU͕ҟͳ ΔͱআͰ͖ͳ͍ w EFWFMPQNFOU༻ͷϚγϯͰQSPEVDUJPOͷ%#Λؒҧͬͯফ͢Έ͍ͨͳͷΛ੍ w %#আ͢ΔFOWJSPONFOUͰCJOSBJMTECFOWJSPONFOUTFUͱ͢Δͱ࣮ߦͰ͖Δɹ
IFSPLVରԠ w ཧ༻ͷςʔϒϧΛ࡞Δඞཁ͕͋Δ w ͳ͍ͱCJOSBJMTECFOWJSPONFOUTFU͠Ζͱౖ ΒΕΔ w ৄͪ͘͜͠Β w IUUQZZBHJUVNCMSDPNQPTUSBJMT&"# &"&"&'EC&"#&"" &###UBTL&"&&#&"% "&"&&"# &"&&"
Provide encrypted secrets $ rails secrets:edit $ Please enter the master key: XXXXXX $ [Rails opens config/secrets.yml.enc in unencrypted form in EDITOR] $ [Saving the opened file will encrypt the file back into config/ secrets.yml.enc] • RAILS_MASTER_KEYがあればそれを使う • デプロイ時はこれ
ActiveJob.retry_on class RemoteServiceJob < ActiveJob::Base retry_on CustomAppException # defaults to 3s wait, 5 attempts retry_on AnotherCustomAppException, wait: ->(executions) { executions * 2 } retry_on(YetAnotherCustomAppException) do |exception| ExceptionNotifier.caught(exception) end retry_on ActiveRecord::StatementInvalid, wait: 5.seconds, attempts: 3 retry_on Net::OpenTimeout, wait: :exponentially_longer, attempts: 10 def perform(*args) # Might raise CustomAppException, AnotherCustomAppException, or YetAnotherCustomAppException for something domain specific # Might raise ActiveRecord::StatementInvalid when a local db deadlock is detected # Might raise Net::OpenTimeout when the remote service is down end end