ã¢ãã«ã®ã¹ã³ã¼ãæ©è½ã¨ã¯ãå
±éçã«ä½¿ãã¯ã¨ãªãã¢ãã«ã®ã¡ã½ããã®ããã«å®ç¾©ã§ããæ©è½ã§ãã ãããããã¨ã«ãããè¤éãªSQLãä½åº¦ãæ¸ããªãã¦ãããªããå¯èªæ§ã¨ä¿å®æ§ãåä¸ããããã¨ãã§ãã¾ãã åä½ç¢ºèª Rails 4.1 ç®æ¬¡ ã¹ã³ã¼ã(Scope)ã®æ¦è¦ ã¹ã³ã¼ãã«å¼æ°ãæå® ã¹ã³ã¼ãã®ãã¼ã¸ ããã©ã«ãã¹ã³ã¼ãã®è¨å® 1. ã¹ã³ã¼ã(Scope)ã®æ¦è¦ä»¥ä¸ã®2ã¤ã®æ¹æ³ã§ãå
±éçã«ä½¿ãã¯ã¨ãªãã¹ã³ã¼ããã¨ãã¦å®ç¾©ã§ãã¾ãã # å®ç¾©æ¹æ³1: scopeã¡ã½ããã§å®ç¾© class Post < ActiveRecord::Base scope :published, -> { where(published: true) } end # å®ç¾©æ¹æ³2: ã¯ã©ã¹ã¡ã½ããã®ããã«å®ç¾© class Post < ActiveRecord::Base def self.published whe
{{#tags}}- {{label}}
{{/tags}}