railsã®modelä¸ã§ä½¿ç¨ããscopeã«ã¤ãã¦ã¡ã¢ãã¾ãã railsã§ã¯ãscopeãã¨è¨ã£ã¦ã以ä¸ã®ããã«è²ã
æãã®ã§æ¸æãã¾ããã modelä¸ã§DBãæ¤ç´¢ããæ¡ä»¶ããããããæºåããããã®ãscopeã routes.rbä¸ã§ä½¿ç¨ãããURLã«namespaceãä»ä¸ããããã®ãscopeã å¤æ°ã®åå空éã®æå¹ç¯å²ã®ãã¨ãæããã¹ã³ã¼ãã ãã®ä»ãã©ã¡ã¼ã¿ã¼è¨å®ç scope(model)ã®ä½¿ãæ¹ ã¢ãã«ã« scope(ã¹ã³ã¼ãå, æ¡ä»¶å¼) ãè¨è¿°ãã¾ãã ã³ã³ããã¼ã©ã¼çã§ããã¢ãã«å.ã¹ã³ã¼ãåãã¨ããã¨ãæ¡ä»¶å¼ãç¨ããDBã¢ã¯ã»ã¹ãè¡ãã¾ãã 使ç¨ä¾â (éé ã§ä¸¦ã³æ¿ãããã¼ã¿ãå¾ãçºã®ã¹ã³ã¼ã) Diaryã¢ãã«ä¸ã«scopeãå®ç¾© class Diary scope :latest, -> { order("updated_at desc") } # â使ç¨ã§
{{#tags}}- {{label}}
{{/tags}}