翻蚳è
ããïŒ 7ã€ã®ãã¿ãŒã³ãšé¡ãããFat ActiveRecord Modelsããªãã¡ã¯ã¿ãªã³ã°ããCode Climateããã°ã®èšäºã®ç¡æ翻蚳ããå±ãããŸãã
Code Climateã¯ãRuby on Railsã¢ããªã±ãŒã·ã§ã³ã®ã³ãŒãå質ãšã»ãã¥ãªãã£ãåæããããã®åŒ·åãªããŒã«ã§ãã
ã¯ããã«
éçºè
ãRailsã³ãŒãã®å質ãæ¹åããããã«
Code Climateã䜿çšãå§ãããšããå€ãã®ã³ãŒããæã€ã¢ãã«ã¯å€§ããªã¢ããªã±ãŒã·ã§ã³ãç¶æãããšãã«åé¡ãåŒãèµ·ãããããã¢ãã«ã®ã³ãŒãã®ãèšåŒµããé¿ããå¿
èŠããããŸãã ãã¡ã€ã³ããžãã¯ãã¢ãã«ã«ã«ãã»ã«åããããšã¯ããã®ããžãã¯ãã³ã³ãããŒã©ãŒã«é
眮ãããããåªããŠããŸããããã®ãããªã¢ãã«ã¯éåžžã
åäžè²¬ä»»ååã«éåããŸãã ããšãã°ããŠãŒã¶ãŒã«é¢é£ãããã¹ãŠã
Userã¯ã©ã¹ã«é
眮ããå Žåããããå¯äžã®è²¬ä»»ã§ã¯ãããŸããã
åæ段éã§SRPã®ååã«åŸãããšã¯éåžžã«ç°¡åã§ããã¢ãã«ã¯ã©ã¹ã¯ããŒã¿ããŒã¹ããã³é¢ä¿ãšã®çžäºäœçšã®ã¿ãå¶åŸ¡ããŸãããåŸã
ã«æé·ããå
ã
ãªããžããªãšã®çžäºäœçšãæ
åœããŠãããªããžã§ã¯ããå®éã«ãã¹ãŠã®ããžãã¹ããžãã¯ã®ææè
ã«ãªããŸãã 1ã2幎åŸããããªãã¯ã€ã³ã¿ãŒãã§ã€ã¹ã«500è¡ãè¶
ããã³ãŒããšæ°çŸã®ã¡ãœãããæã€
Userã¯ã©ã¹ãååŸããŸãã ãã®ã³ãŒããç解ããããšã¯éåžžã«å°é£ã§ãã
ã¢ããªã±ãŒã·ã§ã³ã®å
éšã®è€éããå¢ããšïŒæ©èœã®è¿œå ïŒãå°ããªãªããžã§ã¯ããŸãã¯ã¢ãžã¥ãŒã«ã®ã»ããéã§ã³ãŒããé
åžããå¿
èŠããããŸãã ããã«ã¯ãåžžã«ãªãã¡ã¯ã¿ãªã³ã°ãå¿
èŠã§ãã ãã®ååã«åŸããšãæ確ã«å®çŸ©ãããã€ã³ã¿ãŒãã§ãŒã¹ãåããå°ãããŠå¿çæ§ã®é«ããªããžã§ã¯ãã®ã»ãããã§ããŸãã
Railsã§OOPã®ååã«åŸãããšã¯éåžžã«é£ãããšæããããããŸããã åãããšãèããŸãããããã°ããæéããããŠå®éšããçµæããã¬ãŒã ã¯ãŒã¯ãšããŠã®Railsã¯çµ¶å¯Ÿã«OOPã«å¹²æžããªãããšãããããŸããã å
šäœã®è²¬ä»»ã¯ãRailsã®å¥çŽããŸãã¯ActiveRecordã®è€éãã®ç®¡çïŒåŸãã®ã容æãªã¢ãã«ïŒã管çããå¥çŽã®æ¬ åŠã§ãã 幞ããªããšã«ããã®å Žåããªããžã§ã¯ãæåã®ååãšå®è·µãé©çšã§ããŸãã
ã¢ãã«ããããã¯ã¹ã€ã³ãéžæããªãã§ãã ãã
ãã®ãªãã·ã§ã³ãããã«é€å€ããŸãããã 倧èŠæš¡ãªã¢ãã«ã®ã¡ãœããã®äžéšãæžå¿µãŸãã¯ã¢ãžã¥ãŒã«ã«ç§»åããããšã¯ãå§ãããŸããããããã¯åãã¢ãã«ã«å«ãŸããŸãã ç¶æ¿ãããæ§æãæãŸããã ããã¯ã¹ã€ã³ã䜿çšããããšã¯ãé
ã«ãããŽããæŒããŠæ±ããéšå±ãæé€ãããããªãã®ã§ãã æåã¯ãããã«èŠããŸããããã®ãããªãã³ãŒããŒãã¯ãã¢ãã«å
ã®ãã§ã«è€éãªããžãã¯ã®ç解ãè€éã«ããŸãã
ããããªãã©ãŒãªã³ã°ãå§ããŸãããïŒ
ãªãã¡ã¯ã¿ãªã³ã°
1.å€ãªããžã§ã¯ãã匷調衚瀺ãã
å€ãªããžã§ã¯ãã¯ãå«ãŸããŠããå€ã«ãã£ãŠå¥ã®ãªããžã§ã¯ããšç°¡åã«æ¯èŒã§ããåçŽãªãªããžã§ã¯ãã§ãã éåžžããã®ãããªãªããžã§ã¯ãã¯äžå€ã§ãã æ¥ä»ãURIãããã³ãã¹åã¯Rubyæšæºã©ã€ãã©ãªã®å€ãªããžã§ã¯ãã®äŸã§ãããã¢ããªã±ãŒã·ã§ã³ã¯ãªããžã§ã¯ãïŒãã¡ã€ã³åºæã®å€ïŒãå®çŸ©ã§ããŸãïŒã»ãŒç¢ºå®ã«å®çŸ©ã§ããŸãïŒã ããããã¢ãã«ãšåºå¥ããããšã¯ãæãåçŽãªãªãã¡ã¯ã¿ãªã³ã°ã®1ã€ã§ãã
Railsã§ã¯ãå€ãªããžã§ã¯ãã¯ãé¢é£ããããžãã¯ãæã€å±æ§ãŸãã¯å°ããªå±æ§ã°ã«ãŒããšããŠäœ¿çšããã®ã«æé©ã§ãã ããã¹ããã£ãŒã«ããŸãã¯ã«ãŠã³ã¿ä»¥äžã®å±æ§ã¯ãåå¥ã®ã¯ã©ã¹ãšããŠå²ãåœãŠãããåªããåè£ã§ãã
ããšãã°ãã¡ãã»ãŒãžã³ã°ã¢ããªã±ãŒã·ã§ã³ã§ã¯
PhoneNumberå€
ãªããžã§ã¯ãã䜿çšã§ãããããŒãã©ã³ã¶ã¯ã·ã§ã³ã¢ããªã±ãŒã·ã§ã³ã§ã¯Moneyå€ãªããžã§ã¯ãã䜿çšã§ããŸãã Code Climateã«ã¯ãªããžã§ã¯ãããããŸã-Ratingãšããå€ã§ããããã¯ããã¹ãŠã®ã¯ã©ã¹ãŸãã¯ã¢ãžã¥ãŒã«ãåãåãAããFãŸã§ã®åçŽãªè©äŸ¡ã¹ã±ãŒã«ã§ãã ïŒæåã¯ãããè¡ãããŸããïŒéåžžã®æååã®ã€ã³ã¹ã¿ã³ã¹ã䜿çšã§ããŸãããã
Ratingã¯ã©ã¹ã䜿çšãããšãããŒã¿ã«åäœãè¿œå ã§ããŸãã
class Rating include Comparable def self.from_cost(cost) if cost <= 2 new("A") elsif cost <= 4 new("B") elsif cost <= 8 new("C") elsif cost <= 16 new("D") else new("F") end end def initialize(letter) @letter = letter end def better_than?(other) self > other end def <=>(other) other.to_s <=> to_s end def hash @letter.hash end def eql?(other) to_s == other.to_s end def to_s @letter.to_s end end
ConstantSnapshotã¯ã©ã¹ã®åã€ã³ã¹ã¿ã³ã¹ã¯ã次ã®ããã«ããã®ãããªãã¯ã€ã³ã¿ãŒãã§ã€ã¹ã§è©äŸ¡ãªããžã§ã¯ããžã®ã¢ã¯ã»ã¹ãæäŸããŸãã
class ConstantSnapshot < ActiveRecord::Base
ConstantSnapshotã¯ã©ã¹ã®ãµã€ãºãçž®å°ããããšã«å ããŠããã®ã¢ãããŒãã«ã¯ããã«ããã€ãã®å©ç¹ããããŸãã
- #Worse_thanã¡ãœããïŒ ãš#better_thanïŒ çµã¿èŸŒã¿ã®RubyæŒç®å>ããã³<
- #hashããã³#eqlã¡ãœãããå®çŸ©ããŠããŸããïŒ ã¯ã©ã¹Ratingã®ãªããžã§ã¯ããããã·ã¥ããŒãšããŠäœ¿çšã§ããããã«ããŸãã CodeClimateã¯ããã䜿çšããŠã EnumberableïŒgroup_byã䜿çšããŠè©äŸ¡ããããšã«ãããã¯ã©ã¹ãšã¢ãžã¥ãŒã«ãã°ã«ãŒãåããŸãã
- #to_sã¡ãœããã䜿çšãããšãè¿œå ã®åŽåãªãã§ãã¯ã©ã¹Ratingã®ãªããžã§ã¯ããæååã«è£éã§ããŸã
- ãã®ã¯ã©ã¹ã¯ãæå®ããããä¿®æ£äŸ¡æ ŒãïŒæå®ãããã¯ã©ã¹ã®ãã¹ãŠã®ãåãããé€å»ããã®ã«å¿
èŠãªæéïŒã«å¯Ÿããæ£ããè©äŸ¡ãè¿ããã¡ã¯ããªã¡ãœããã®äŸ¿å©ãªå Žæã§ãã
2.ãµãŒãã¹ãªããžã§ã¯ãã®éžæïŒãµãŒãã¹ãªããžã§ã¯ãïŒ
ã·ã¹ãã ã®äžéšã®ã¢ã¯ã·ã§ã³ã¯ããµãŒãã¹ãªããžã§ã¯ããžã®ã«ãã»ã«åãæ£åœåããŸãã ã¢ã¯ã·ã§ã³ã1ã€ä»¥äžã®åºæºãæºããå Žåããã®ã¢ãããŒãã䜿çšããŸãã
- è€éãªã¢ã¯ã·ã§ã³ïŒããšãã°ãäŒèšæéã®çµããã«å
åž³ãéããïŒ
- ã¢ã¯ã·ã§ã³ã«ã¯ãããã€ãã®ã¢ãã«ã§ã®äœæ¥ãå«ãŸããŸãïŒããšãã°ãé»å賌å
¥ã«ã¯Order ã CreditCardããã³Customerã¯ã©ã¹ã®ãªããžã§ã¯ããå«ãŸããå ŽåããããŸãïŒ
- ã¢ã¯ã·ã§ã³ã¯å€éšãµãŒãã¹ãšå¯Ÿè©±ããŸãïŒããšãã°ããœãŒã·ã£ã«ãããã¯ãŒã¯ã§ã®å
±æïŒ
- ã¢ã¯ã·ã§ã³ã¯ãåºç€ãšãªãã¢ãã«ã«çŽæ¥é¢é£ããŠããŸããïŒããšãã°ãäžå®æéåŸã«æéåãã®æ³šæãã¯ãªã¢ãããªã©ïŒ
- ãã®ã¢ã¯ã·ã§ã³ãå®è¡ããã«ã¯ãããã€ãã®æ¹æ³ããããŸãïŒã¢ã¯ã»ã¹ããŒã¯ã³ãŸãã¯ãã¹ã¯ãŒãã䜿çšããèªèšŒãªã©ïŒã ãã®å ŽåãGoFãã¿ãŒã³æŠç¥ã䜿çšããå¿
èŠããããŸãã
ããšãã°ã
UserïŒauthenticateã¡ãœããã
UserAuthenticatorã¯ã©ã¹ã«è»¢éã§ã
ãŸã ã
class UserAuthenticator def initialize(user) @user = user end def authenticate(unencrypted_password) return false unless @user if BCrypt::Password.new(unencrypted_password) == @user.password_digest @user else false end end end
ãã®å Žåã
SessionsControllerã¯æ¬¡ã®ããã«ãªããŸãã
class SessionsController < ApplicationController def create user = User.where(email: params[:email]).first if UserAuthenticator.new(user).authenticate(params[:password]) self.current_user = user redirect_to dashboard_path else flash[:alert] = "Login failed." render "new" end end end
3.ãã©ãŒã ãªããžã§ã¯ãã®éžæïŒãã©ãŒã ãªããžã§ã¯ãïŒ
1ã€ã®ãã©ãŒã éä¿¡ã§è€æ°ã®ã¢ãã«ãæŽæ°ã§ããå Žåããã®ã¢ã¯ã·ã§ã³ã¯ãã©ãŒã ãªããžã§ã¯ãã«ã«ãã»ã«åã§ããŸãã ããã¯ã
accepts_nested_attributes_forã䜿çšããããããã£ãšãããã§ãã è¯ãäŸã¯ãç»é²ãã©ãŒã ã®éä¿¡ã§ãããã®çµæã
äŒç€Ÿãš
ãŠãŒã¶ãŒã®ã¬ã³ãŒããäœæããå¿
èŠããã
ãŸã ã
class Signup include Virtus extend ActiveModel::Naming include ActiveModel::Conversion include ActiveModel::Validations attr_reader :user attr_reader :company attribute :name, String attribute :company_name, String attribute :email, String validates :email, presence: true
ActiveRecordãšåæ§ã®å±æ§åäœãå®çŸããããã«ãgem
Virtusã䜿çšããŸãã ãã©ãŒã ãªããžã§ã¯ãã¯éåžžã®ã¢ãã«ã®ããã«èŠãããããã³ã³ãããŒã©ãŒã¯å€æŽãããŸããã
class SignupsController < ApplicationController def create @signup = Signup.new(params[:signup]) if @signup.save redirect_to dashboard_path else render "new" end end end
瀺ãããŠããäŸã®ããã«ãããã¯åçŽãªå Žåã«ã¯ããŸãæ©èœããŸãããããŒã¿ããŒã¹ãšå¯Ÿè©±ããããžãã¯ãè€éã«ãªããããå Žåããã®ã¢ãããŒãããµãŒãã¹ãªããžã§ã¯ãã®äœæãšçµã¿åãããããšãã§ããŸãã ããã«ãæ€èšŒã¯å€ãã®å Žåã³ã³ããã¹ãäŸåã§ããããããã¹ãŠã®æ€èšŒãã¢ãã«ã«å
¥ããã®ã§ã¯ãªãã䜿çšå Žæã§çŽæ¥æ±ºå®ã§ããŸããããšãã°ããŠãŒã¶ãŒã®ãã¹ã¯ãŒãã®æ€èšŒã¯ãæ°ãããŠãŒã¶ãŒãäœæãããšããšãã¹ã¯ãŒããå€æŽãããšãã«ã®ã¿å¿
èŠã§ããããããŠãŒã¶ãŒããŒã¿ãå€æŽããããã³ã«ããã確èªããå¿
èŠããããŸãïŒãŠãŒã¶ãŒããŒã¿ã®å€æŽãšãã¹ã¯ãŒãã®å€æŽãã©ãŒã ã1ã€ã®ãã¥ãŒã«å
¥ããªãã®ã§ããïŒïŒ
4.ã¯ãšãªãªããžã§ã¯ãã®åŒ·èª¿è¡šç€º
è€éãªSQLã¯ãšãªãïŒéçã¡ãœãããšã¹ã³ãŒãã«ïŒè¡šç€ºãããå Žåãããããå¥ã®ã¯ã©ã¹ã«å
¥ãã䟡å€ããããŸãã åèŠæ±ãªããžã§ã¯ãã¯ãç¹å®ã®ããžãã¹ã«ãŒã«ã«åŸã£ãŠéžæãè¡ããŸãã ããšãã°ããªããžã§ã¯ã-å®äºããè©ŠçšæéïŒ
æããã«Code Climateã«æ
£ããè©Šçšæéãæå³ããïŒãèŠã€ããããã®èŠæ±ã¯æ¬¡ã®ããã«ãªããŸãã
class AbandonedTrialQuery def initialize(relation = Account.scoped) @relation = relation end def find_each(&block) @relation. where(plan: nil, invites_count: 0). find_each(&block) end end
ãã®ãããªã¯ã©ã¹ã¯ããã¯ã°ã©ãŠã³ãã§äœ¿çšããŠãæçŽãéä¿¡ã§ããŸãã
AbandonedTrialQuery.new.find_each do |account| account.send_offer_for_support end
ActiveRecord :: Relationã¯ã©ã¹ã®ã¡ãœããã䜿çšãããšãæ§æã䜿çšããŠã¯ãšãªãçµåããã®ã«äŸ¿å©ã§ãã
old_accounts = Account.where("created_at < ?", 1.month.ago) old_abandoned_trials = AbandonedTrialQuery.new(old_accounts)
ãã®ãããªã¯ã©ã¹ããã¹ããããšãã¯ãæ£ããé åºã§è¡ã®ã¯ãšãªçµæãšããŒã¿ããŒã¹ããã®éžæã確èªããå¿
èŠããããŸãããŸããçµåãšè¿œå ã¯ãšãªã®ååšã確èªããå¿
èŠããããŸãïŒN + 1ã¯ãšãªãªã©ã®ãã°ãåé¿ããããïŒã
5.ãªããžã§ã¯ãã®è¡šç€º
äžéšã®ã¡ãœããããã¬ãŒã³ããŒã·ã§ã³ã§ã®ã¿äœ¿çšãããå Žåããããã¯ã¢ãã«ã¯ã©ã¹ã«é
眮ãããŸããã ãé³å£°é§åãªã©ããã®ã¢ããªã±ãŒã·ã§ã³ã®ä»£æ¿ã€ã³ã¿ãŒãã§ã€ã¹ãå®è£
ããå Žåããã®æ¹æ³ãå¿
èŠã§ããïŒããšèªåããŠãã ããã ããã§ãªãå Žåã¯ããã«ããŒãŸãã¯ïŒããã«è¯ãïŒãã¥ãŒãªããžã§ã¯ãã«è»¢éããå¿
èŠããããŸãã
ããšãã°ãCode Climateã®ããŒããã°ã©ãã¯ãã³ãŒãã®ç¶æ
ã®ã¹ãããã·ã§ããã«åºã¥ããŠã¯ã©ã¹è©äŸ¡ãåé¡ããŸãã ãããã®ã¢ã¯ã·ã§ã³ã¯ã次ã®åœ¢åŒã®ãªããžã§ã¯ãã«ã«ãã»ã«åãããŸãã
class DonutChart def initialize(snapshot) @snapshot = snapshot end def cache_key @snapshot.id.to_s end def data
ãã¥ãŒãšERBïŒãŸãã¯Haml / SlimïŒãã¿ãŒã³ãšã®éã«1察1ã®é¢ä¿ãããããšããããããŸãã ããã«ããã
2ã¹ããããã¥ãŒãã³ãã¬ãŒãã䜿çšãããšããã¢ã€ãã¢ãåŸãããŸããããRailsã®å®åŒåããããœãªã¥ãŒã·ã§ã³ã¯ãŸã ãããŸããã
æ³šïŒ ããã¬ãŒã³ã¿ãŒããšããçšèªã¯Rubyã³ãã¥ããã£ã§åãå
¥ããããŠããŸããããã®ææ§ãã®ããã«ç§ã¯ãããé¿ããŠããŸãã ããã¬ãŒã³ã¿ãŒããšããçšèªã¯ãç§ããªããžã§ã¯ããšåŒã¶ãã®ãã€ãŸããã©ãŒã ãèšè¿°ããããã«
ãžã§ã€ã»ãã£ãŒã«ãºã«ãã£ãŠææ¡ãããŸãã ã ããã«ãRailsã§ã¯ããã¥ãŒããšããçšèªã䜿çšããŠãäžè¬ã«ããã³ãã¬ãŒãããšåŒã°ãããã®ã説æããŠããŸãã ãããŸãããé¿ããããããã¥ãŒãªããžã§ã¯ããããã¥ãŒã¢ãã«ããšåŒã¶ããšããããŸãã
6.ã«ãŒã«ãªããžã§ã¯ãã®éžæïŒããªã·ãŒãªããžã§ã¯ãïŒ
è€éãªèªã¿åãæäœã«ã¯ãåå¥ã®ãªããžã§ã¯ããå¿
èŠãªå ŽåããããŸãã ãã®ãããªå Žåãããªã·ãŒãªããžã§ã¯ãã䜿çšããŸãã ããã«ãããããšãã°ããŠãŒã¶ãŒã®ã¢ã¯ãã£ããã£ããã§ãã¯ãããªã©ãã¢ãã«ãããµã€ãããžãã¯ãåé€ã§ããŸãã
class ActiveUserPolicy def initialize(user) @user = user end def active? @user.email_confirmed? && @user.last_login_at > 14.days.ago end end
ãã®ãããªãªããžã§ã¯ãã¯ããŠãŒã¶ãŒã®é»åã¡ãŒã«ãæ€èšŒããããã©ãããããã³ãŠãŒã¶ãŒãéå»2é±éã«ã¢ããªã±ãŒã·ã§ã³ã䜿çšãããã©ããããã§ãã¯ãã1ã€ã®ããžãã¹ã«ãŒã«ãã«ãã»ã«åããŸãã ã«ãŒã«ãªããžã§ã¯ãã䜿çšããŠãè€æ°ã®ããžãã¹ã«ãŒã«ãã°ã«ãŒãåããããšãã§ããŸããããšãã°ããŠãŒã¶ãŒãã¢ã¯ã»ã¹ã§ããããŒã¿ã決å®ããAuthorizerãªããžã§ã¯ããªã©ã§ãã
ã«ãŒã«ãªããžã§ã¯ãã¯ãµãŒãã¹ãªããžã§ã¯ãã«äŒŒãŠããŸãããæžã蟌ã¿æäœã«ã¯ããµãŒãã¹ãªããžã§ã¯ãããšããçšèªã䜿çšããèªã¿åãæäœã«ã¯ããªããžã§ã¯ãã«ãŒã«ããšããçšèªã䜿çšããŸãã ã¯ãšãªãªããžã§ã¯ãã«ã䌌ãŠããŸãããã¯ãšãªãªããžã§ã¯ãã¯SQLã¯ãšãªãå®è¡ããŠçµæãè¿ãããã«ã®ã¿äœ¿çšãããã«ãŒã«ãªããžã§ã¯ãã¯æ¢ã«ã¡ã¢ãªã«ããŒããããŠãããã¡ã€ã³ã¢ãã«ã§åäœããŸãã
7.ãã³ã¬ãŒã¿ãŒã®åŒ·èª¿è¡šç€º
ãã³ã¬ãŒã¿ã䜿çšãããšãæ¢åã®æäœã§æ©èœãæ§ç¯ã§ãããããã³ãŒã«ããã¯ã«å¹æã䌌ãŠããŸãã ã³ãŒã«ããã¯ããžãã¯ã1å䜿çšããå ŽåããŸãã¯ã¢ãã«ã«å«ããã®ã«å€ãã®è²¬ä»»ã䌎ãå Žåã¯ããã³ã¬ãŒã¿ãŒã䜿çšãããšäŸ¿å©ã§ãã
ããã°æçš¿ã«ã³ã¡ã³ããäœæãããšãFacebookã®å£ã«ã³ã¡ã³ããäœæãããå ŽåããããŸãããããã¯ããã®ããžãã¯ã
Commentã¯ã©ã¹ã«å«ãŸããŠããå¿
èŠããããšããæå³ã§ã¯ãããŸããã äœéã§è匱ãªãã¹ãããŸãã¯ç¡é¢ä¿ãªãã¹ãã§ã®å¥åŠãªå¯äœçšã¯ãã³ãŒã«ããã¯ã«ããŸãã«ãå€ãã®ããžãã¯ãå
¥ããŠããå
åã§ãã
Facebookã³ã¡ã³ãã®ã³ã¡ã³ãããžãã¯ããã³ã¬ãŒã¿ã«é
眮ããæ¹æ³ã¯æ¬¡ã®ãšããã§ãã
class FacebookCommentNotifier def initialize(comment) @comment = comment end def save @comment.save && post_to_wall end private def post_to_wall Facebook.post(title: @comment.title, user: @comment.author) end end
ã³ã³ãããŒã©ãŒã¯æ¬¡ã®ããã«ãªããŸãã
class CommentsController < ApplicationController def create @comment = FacebookCommentNotifier.new(Comment.new(params[:comment])) if @comment.save redirect_to blog_path, notice: "Your comment was posted." else render "new" end end end
ãã³ã¬ãŒã¿ã¯ãæ¢åã®ãªããžã§ã¯ãã®æ©èœãæ¡åŒµããããããªããžã§ã¯ã-ãµãŒãã¹ãšã¯ç°ãªããŸãã ã©ããåŸããã³ã¬ãŒã¿ãªããžã§ã¯ãã¯éåžžã®
Commentãªããžã§ã¯ããšåãæ¹æ³ã§äœ¿çšãããŸãã Rubyæšæºã©ã€ãã©ãªã¯ãã¡ã¿ããã°ã©ãã³ã°ã䜿çšããŠ
ãã³ã¬ãŒã¿ã®äœæãç°¡çŽ åããããŒã«ã®ã»ãããæäŸããŸãã
ãããã«
Railsã¢ããªã±ãŒã·ã§ã³ã§ããã¢ãã«ã®è€éããå¶åŸ¡ããå€ãã®æ©èœããããŸãã ãããããã¬ãŒã ã¯ãŒã¯ã®ååã«éåããå¿
èŠã¯ãããŸããã
ActiveRecordã¯åªããã©ã€ãã©ãªã§ãããããã ãã«äŸåããŠãããšå€±æããããšããããŸãã ã©ã€ãã©ãªãŸãã¯ãã¬ãŒã ã¯ãŒã¯ã«ãã£ãŠãã¹ãŠã®åé¡ã解決ã§ããããã§ã¯ãããŸããã ã¢ãã«ãããŒã¿ããŒã¹ãšã®çžäºäœçšã®ããžãã¯ã®ã¿ã«å¶éããŠãã ããã æ瀺ãããææ³ã䜿çšãããšãã¢ãã«ã®ããžãã¯ãé
åžãããã®çµæãä¿å®ããããã¢ããªã±ãŒã·ã§ã³ãååŸã§ããŸãã
説æãããŠãããã³ãã¬ãŒãã®ã»ãšãã©ã¯éåžžã«ã·ã³ãã«ã§ããããããã®ãªããžã§ã¯ãã¯åãªãOld Old Ruby ObjectïŒPOROïŒã§ãããRailsã§OOPã¢ãããŒãã䜿çšããããšã®äŸ¿å©ããå®å
šã«ç€ºããŠããããšã«ãæ°ã¥ãã§ãããã