railsã®flashã«ã¤ãã¦ãããå¿ããã®ã§ã¡ã¢ã
â»ããã§è¨ãflashã¯ãMacromedia Flashã¨ã¯å
¨ãé¢ä¿ãªããRailsã®ã»ãã·ã§ã³ãå©ç¨ããæ©è½ã®flashã«ã¤ãã¦ã
flash ã¨ã¯ï¼
- ãã°ã¤ã³æã®ã¦ã§ã«ã«ã ã¡ãã»ã¼ã¸ããé ç®è¿½å ã®æåéç¥ãªã©ãã¦ã¼ã¶ã«ç°¡åãªéç¥ãè¡ãããæã«å©ç¨ããã
- ã³ã³ããã¼ã©ã§flashã¡ãã»ã¼ã¸ãè¨å®ãããã¥ã¼ã§è¡¨ç¤ºããã
- flashã¯å ¨ä½ã§è¦ãã°Hashããããã¼ã«å¯¾ããå¤ã¨ãã¦ã¡ãã»ã¼ã¸ãè¨å®ããããã¼ã¯èªç±ã«è¨å®ã§ããããããã©ã«ãã¨ãã¦alertã¨noticeãããã
- è¨å®ããã¡ãã»ã¼ã¸ã¯ãsessionã«ä¿åããããã¤ã¾ããflashã¯ãsessionãå©ç¨ããæ©è½ã®ï¼ã¤ã
- æ®éã®ã»ãã·ã§ã³å¤æ°ã§ã¯ç ´æ£ããã¾ã§å¤ã¯ä¿æãããããflash ã®å ´åã¯ä¸åº¦è¡¨ç¤ºãããã¨ã¢ã¯ã·ã§ã³çµäºæã«èªåçã«æ¶å»ãããã
使ãæ¹
ã³ã³ããã¼ã©ã§å®ç¾©
flash[:notice] = "hogehoge"
redirect_toã®ãªãã·ã§ã³ã¨ãã¦ãä»å ã§ããã
redirect_to :root, :flash => {:error => "errorãèµ·ãã¾ãã"}
ãã¥ã¼ã§è¡¨ç¤º
<%= flash[:alert] %>
Rails2.xç³»ã§ã¯ãnoticeã¨alertãããã©ã«ãã
ä¾ãã°ãredirect_toã®ã¨ãã¯ãä¸è¨ã®ããã«æ¸ããã
redirect_to :root, :notice => "hello" redirect_to :root, :alert => "errorãèµ·ãã¾ãã"
flashã®ç¨®é¡
flash
- ä¸åº¦è¡¨ç¤ºãããã¾ã§å¤ãä¿æãããã
- ãã®ãããäºæããªãã¡ãã»ã¼ã¸ã表示ãã¦ãã¾ããã¨ãããã®ã§æ³¨æã
- ãã®ã¢ã¯ã·ã§ã³èªä½ãããªãã¤ã¬ã¯ããã次ã®ã¢ã¯ã·ã§ã³ã§å©ç¨ã
- ä¸åº¦è¡¨ç¤ºãããæç¹ã§ç ´æ£ãããã
flash.now
- å®ç¾©ããã¡ã½ããå ï¼åããªã¯ã¨ã¹ãå ï¼ã§ã®ã¿æå¹ã
- ã¡ã½ãã1ã§å®ç¾©ããå ´åãã¡ã½ãã2ã§ã¯å©ç¨ä¸å¯ã
- redirectãããå ã§ã¯è¡¨ç¤ºãããªãã
使ãæ¹
- ã³ã³ããã¼ã©
flash.now[:notice] = "hello"
- ãã¥ã¼
<%= flash[:notice] %>
flash.keep
- æ®éflashã¯ä¸åº¦è¡¨ç¤ºãããã¨æ¶ããããflash.keepã§è¨å®ããã°ãå¤ãä¿æãç¶ããã
- å¼æ°ãªã㧠.keep ãæå®ããã°ãã¹ã¦ã® flash ãä¿æãããã
使ãæ¹
- ã³ã³ããã¼ã©
flash[:notice] = "hoge" flash.keep(:notice) #å¼æ°ãªãã§ãflash.keepã¨ããã°ãå ¨ã¦ã®flashã®å¤ãkeepãããã
- ãã¥ã¼
<%= flash[:notice] %>
åç §
Rails3ã¬ã·ããã㯠190ã®æ
- ä½è : é«æ©å¾ç¾©,æ¾ç°æ,諸æ©æä»
- åºç社/ã¡ã¼ã«ã¼: ã½ãããã³ã¯ã¯ãªã¨ã¤ãã£ã
- çºå£²æ¥: 2011/07/25
- ã¡ãã£ã¢: åè¡æ¬
- è³¼å ¥: 34人 ã¯ãªãã¯: 966å
- ãã®ååãå«ãããã° (38件) ãè¦ã
ãèªã¿é ããããã¨ããããã¾ãã
ããããã°ã®å 容ãæ°ã«å¬ãã¾ããããRSSãªã¼ãã¼ã«ãç»é²ãã¦é ããã¨å¹¸ãã§ãããããããé¡ããã¾ãã
twitter@kbktããã£ã¦ã¾ããITç³»ã®ææ°æ å ±ãã©ã¤ãããã¯æ å ±ãããã¤ã¶ããã¦ãã¾ãããããããã°ãã©ãã¼ãã¦ãã ããã
ãããã
ââãã®ããã°ã®ãµã¤ããããã¸ââ