Upgrade to Pro — share decks privately, control downloads, hide ads and more …

7年目を迎えたRails アプリケーションの傾向と対策/Rails Developers Me...

taogawa
March 22, 2019

7年目を迎えたRails アプリケーションの傾向と対策/Rails Developers Meetup 2019 Day1

Rails Developers Meetup 2019でお話した「7年目を迎えたRails アプリケーションの傾向と対策」のスライドです。

taogawa

March 22, 2019
Tweet

More Decks by taogawa

Other Decks in Programming

Transcript

  1. ͷιϦϡʔγϣϯͰ໰୊ͷΛղܾͰ͖Δ w $P$ ઃఆΑΓن໿ Ͱ൥ࡶͳઃఆϑΝΠϧΛল ུ w .PEFMͱςʔϒ ϧͷಉҰࢹ "DUJWF3FDPSEύλʔ

    ϯ ͰϚοϐϯάΛγϯϓϧʹ w ͳͲͳͲɾɾɾ3BJMTͷ͢͹Β͠͞ͷͻͱͭ͸ɺ ͦͷେ୾ʹׂΓ੾ͬͨઃܭࢥ૝
  2. ͍͔ͭ͘ͷʮϨʔϧΛͪΐͬͱ͸ͣΕͨʯ ఆ൪ύλʔϯ͕͋Δ w ංେԽͨ͠"DUJWF3FDPSEϞσϧΛϦϑΝΫλϦϯά͢ Δͭͷํ๏ w IUUQTUFDISBDIPCQTJODKQ IBDIJ@@ ຋༁ 

    w IUUQTDPEFDMJNBUFDPNCMPHXBZTUP EFDPNQPTFGBUBDUJWFSFDPSENPEFMT ݪจ  w ೥Ҏ্લ͚ͩͲݹͼͳ͍ఆ൪ͷهࣄ
  3. 7JFX.PEFM 1SFTFOUFS ͷఆٛ class ProductPresenter # ... def price discount?

    ? @product.discount_price : @product.price end def discount? @user.paid_member? && @product.member_only_discount? end end
  4. Α͋͘Δ֬ೝνΣοΫ # view = form_for(@event, url:foo_path(@event), method: 'patch') do |f|

    = f.hidden_field :event_id = text_area_tag :body = check_box_tag :confirmed # 確認チェック = f.submit "予約をキャンセル" # controller # パラメータのチェックが複数あると見通しが悪くなる if params[:confirmed] == "1" # ... else # ... end
  5. $POUSPMMFS͕͖ͬ͢Γʂ # before if params[:confirmed] == "1" # ... else

    # ... end # after @event_cancellation_form = EventCancellationMessageForm.new(cancellation_message_params) # パラメータチェックが複数あってもFormModel内で処理できる if @event_cancellation_form.valid? # ... end
  6. ͞ΒʹɺԠ༻΋ར͘ΜͰ͢ # view = form_for @bulk_schedule_form, url:schedules_path, method: "post" do

    |f| = f.fields_for :schedules do |s| # ... =f.submit "一括登録" # form_model class BulkScheduleForm includes Activemodel::Model attr_accessor: schedules # ... def schedule_attributes=(attributes) self.schedules = attributes.map do |schedule_attributes| schedule.new(schedule_attributes) end end end
  7. 4FSWJDF0CKFDUͷఆٛ # service_object class EventCreateService def initialize(params) # ... end

    def call # ... end end # controller service = EventCreateService.new(event_params) service.call if service.success? # ... end
  8. ͋ͳͨͷαʔϏε͸ͲͷαʔϏεʁ w ͦ΋ͦ΋&SJD&WBOTͷ%%%ຊͰͷαʔϏεఆ͕ٛ෯޿͍ w ΞϓϦέʔγϣϯαʔϏε w υϝΠϯαʔϏε w ΠϯϑϥετϥΫνϟαʔϏε w

    1PG&""ͷαʔϏεϨΠϠʔ w ͍͍ײ͡ͷศརϝιουͱͯ͠4FSWJDF͕࢖ΘΕΔ w ͜ͷ఺Λҙ͍ࣝͯ͠ͳ͍ͱɺ࿩͕͔Έ߹Θͳ͍