Share
Embed
Transcript
45 slides
-
ίʔϧόοΫνΣʔϯͷఀࢭ ݅ͷมߋ • 有名なやつ • コールバックの停止条件が「false を返す」から 「throw(:abort)」になった • 4.2からアップグレードした人は後方互換性を保った設定
になっているはず • config/initializers/new_framework_default.rb に 設定ある w IUUQSBJMTHVJEFTKQVQHSBEJOH@SVCZ@PO@SBJMTIUNMUISPXBCPSU &"&#&#$&"#&&&"' &&"&#$&#&&$&"% "&&# -
belongs_toのrequired オプションがデフォルトに • Rails 4.2より belongs_to :user, required: true として関連先の存在を調べるバリデーションを定義で
きた • 5.0 からはデフォルトで required: true • オフにしたい場合は optional: true • 4.2からアップグレードした人は後方互換性を保った 設定になっているはず • config/initializers/new_framework_default.rb に設定ある -
։ൃதͷΩϟογϡͷ ΦϯΦϑΓସָ͕͑ʹ # Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=172800' } else config.action_controller.perform_caching = false config.cache_store = :null_store end DPOpHFOWJSPONFOUTEFWFMPQNFOUSC -
production 環境での起動後 は自動読み込みが無効になる • http://railsguides.jp/ upgrading_ruby_on_rails.html#production- %E7%92%B0%E5%A2%83%E3%81%A7%E3%81%AE%E8%B5%B7%E5%8B %95%E5%BE%8C%E3%81%AF%E8%87%AA%E5%8B%95%E8%AA%AD %E3%81%BF%E8%BE%BC%E3%81%BF%E3%81%8C%E7%84%A1%E5%8A %B9%E3%81%AB%E3%81%AA%E3%82%8B
• レアケースだけど、config.autoload_paths << ‘lib' のみ だとはまる可能性あり • ↑↑では Rails.application.config.enable_dependency_loadingをtrue に設定してくださいって書いてあるけど、 config.eagerload_paths << ‘lib’としておくだけで解決で きるケースが多そう -
production 環境での起動後 は自動読み込みが無効になる • そもそも自動読み込みがなんなのか知らないとまずい • しかし説明大変なので自動読み込み関連のリンクだけ 示します • 別の機会で喋るかも
• https://esa-pages.io/p/sharing/2927/posts/ 62/7b7a658a0e590d051c42-slides.html#/ • http://qiita.com/jnchito/items/ 79aaca1c51a0ca20ba6e -
ಛఆͷςʔϒϧͷϨίʔυͷ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ͷϞσϧͷ͏ͪɺͲͷଐੑʹΞΫη ε͍ͯ͠Δ͔ΛऔಘͰ͖ΔΑ͏ʹͳͬͨ 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ରԠ DPOpHFOWJSPONFOUTQSPEVDUJPOSC config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end -
IFSPLVରԠ w IFSPLVͰɺQSPEVDUJPOͷ%#ফͪ͠ΌͬͨΜ͚ͩͲͳΜͱ͔෮چͰ͖ͳ͍ʁΈ ͍ͨͳ͍߹Θ͕ͤ݁ߏ͋ΔΒ͘͠ɺͦΕΛݮΒͨ͢Ίͷमਖ਼͕ೖͬͨ w SBJMTECESPQͳͲͷ%#ഁյܥλεΫ͕QSPEVDUJPOڥͰؒҧ࣮͑ͯߦͯ͠͠· ͏ͷΛࢭ w %*4"#-&@%"5"#"4&@&/7*30/.&/5@$)&$,ɹͱ͢Δͱ࣮ߦͰ͖Δ w
Ұ൪࠷ޙʹ%#Λϩʔυͨ͠FOWJSPONFOUͱɺআ͢Δ%#ͷFOWJSPONFOU͕ҟͳ ΔͱআͰ͖ͳ͍ w EFWFMPQNFOU༻ͷϚγϯͰQSPEVDUJPOͷ%#Λؒҧͬͯফ͢Έ͍ͨͳͷΛ੍ w %#আ͢ΔFOWJSPONFOUͰCJOSBJMTECFOWJSPONFOUTFUͱ͢Δͱ࣮ߦͰ͖Δɹ -
IFSPLVରԠ w ཧ༻ͷςʔϒϧΛ࡞Δඞཁ͕͋Δ w ͳ͍ͱCJOSBJMTECFOWJSPONFOUTFU͠Ζͱౖ ΒΕΔ w ৄͪ͘͜͠Β w IUUQZZBHJUVNCMSDPNQPTUSBJMT&"#
&"&"&'EC&"#&"" &###UBTL&"&&#&"% "&"&&"# &"&&" -
SourceMaps • JavaScriptファイルの多いアプリケーションの開 発が便利になる • Sprockets 3までは、開発中はデフォルトでファ イルの結合をしない • ファイルが増えると遅い
• しかし結合するとエラー箇所が特定しにくい • Sprockets 4からはファイルを結合してもエラー 箇所を特定できるようになった -
Manifest.js • これまでは application.js, application.css 以外のファイルが欲しいときに config.assets.precompile += [‘a.js’, ’b,js’,
’c,js’] みたいに application.rb に書いてた • これからは manifest.js に書く -
Drop jQuery as a dependency • jQuery依存からの脱却 • https://github.com/rails/jquery-ujs/pull/ 474
• PR attathed(WIP) • jquery-ujs -> rails-ujs -
Provide encrypted secrets • config/secrets.ymlの改善 • config/secrets.yml.encに暗号化された秘密 の文字列を書く • 秘密鍵で複合化
• https://github.com/rails/rails/issues/25095 • no PR -
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