Railsã§renderåã«å ±éå¦çãå ¥ãããã¦
ä¸è¦§è¡¨ç¤ºãããéã«ããã°ã¤ã³ã¦ã¼ã¶ã«å¿ãã¦ä¸è¦§ãã«ã¹ã¿ãã¤ãºãããã£ãã
è¤æ°ã³ã³ããã¼ã©ã§åãå¦çãå¿
è¦ã ã£ãã®ã§after_actionã§å®è£
ãã¦ã¿ããã©æå¾
éãã«åããªãï¼ãªãã§ãï¼
ã¨æã£ãããrenderã®å¾ã«after_actionãå®è¡ãããã¨ãããªãã§ããã
ã§ãrenderåã«å¦çãå
¥ããä»çµã¿ãªããã ã£ãï¼ã¨èª¿ã¹ããã ãã©ãçµå±èªåå®è£
ãããªãã«ã
renderããªã¼ãã¼ã©ã¤ã
ã±ã£ã¨æãã¤ãã¦ã»ã«ãå´ä¸ã
ã¢ã¯ã·ã§ã³å¤å®ããªãã¨ãããªããã¤ã±ã¦ãªãããªã¼ã¨æã£ãããã
class IndexCustomizedController < ApplicationController def customize ... end def render(*args) customize if @_action_name == "index" super end end
before_render
ãã¼ããããããã£ã±ãããããã
Rails5ç³»ã®æ
å ±ãè¦ã¤ãããªãã£ããã©åèã«ã§ãããã
æãã¨ã©ã¾ã£ã¦èªåå®è£
ããã§ãã¡ãã£ã¨å¾
ã¦ã
ãã¬ã¼ã ã¯ã¼ã¯ã«æãå
¥ãã¦ã¾ã§ãããã¨ã...?ã¨æãã¨ã©ã¾ã£ãã
(AOPçã«ã¯renderåãããã¯ãã¤ã³ãã¨èªèããããã ãããï¼)
ãããbefore_renderãããã¨ãã³ã¼ããèªãã¨ãã«ãã®åå¨ãè¦ãã¦èªã¾ãªãã¨ãããªãã®ã§*_actionã¨ã¯éã£ã¦å¯èªæ§ãè½ã¡ããã
ã¨ãããã¨ã§çµå±moduleãå®ç¾©ãããã¨ã«ããã
class MyController < ApplicationController def index ... custom_data = IndexCustomizer.costom(user, data) ... end ... end