The Flash

原创 2016年05月30日 17:06:19


flash.now[:error] = ""
render :new


flash[:error] = ""
redirect videos_path



http://guides.rubyonrails.org/action_controller_overview.html

The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for passing error messages etc.

It is accessed in much the same way as the session, as a hash (it's a FlashHash instance).

Let's use the act of logging out as an example. The controller can send a message which will be displayed to the user on the next request:

class LoginsController < ApplicationController
  def destroy
    session[:current_user_id] = nil
    flash[:notice] = "You have successfully logged out."
    redirect_to root_url
  end
end

Note that it is also possible to assign a flash message as part of the redirection.

You can assign :notice:alert or the general purpose :flash:

redirect_to root_url, notice: "You have successfully logged out."
redirect_to root_url, alert: "You're stuck here!"
redirect_to root_url, flash: { referral_code: 1234 }

The destroy action redirects to the application's root_url, where the message will be displayed. Note that it's entirely up to the next action to decide what, if anything, it will do with what the previous action put in the flash. It's conventional to display any error alerts or notices from the flash in the application's layout:

<html>
  <!-- <head/> -->
  <body>
    <% flash.each do |name, msg| -%>
      <%= content_tag :div, msg, class: name %>
    <% end -%>
 
    <!-- more content -->
  </body>
</html>

This way, if an action sets a notice or an alert message, the layout will display it automatically.

You can pass anything that the session can store; you're not limited to notices and alerts:

<% if flash[:just_signed_up] %>
  <p class="welcome">Welcome to our site!</p>
<% end %>

If you want a flash value to be carried over to another request, use the keep method:

class MainController < ApplicationController
  # Let's say this action corresponds to root_url, but you want
  # all requests here to be redirected to UsersController#index.
  # If an action sets the flash and redirects here, the values
  # would normally be lost when another redirect happens, but you
  # can use 'keep' to make it persist for another request.
  def index
    # Will persist all flash values.
    flash.keep
 
    # You can also use a key to keep only some kind of value.
    # flash.keep(:notice)
    redirect_to users_url
  end
end
5.2.1 flash.now

By default, adding values to the flash will make them available to the next request, but sometimes you may want to access those values in the same request.

For example, if the create action fails to save a resource and you render the new template directly,

that's not going to result in a new request, but you may still want to display a message using the flash.

To do this, you can use flash.now in the same way you use the normal flash:

class ClientsController < ApplicationController
  def create
    @client = Client.new(params[:client])
    if @client.save
      # ...
    else
      flash.now[:error] = "Could not save client"
      render action: "new"
    end
  end
end



Flash builder 、flash cs6、 as 3.0研究

1、Flash/Actionscript3 载入资源文件方法考  http://zengrong.net/post/1107.htm
  • yinhaijing123
  • yinhaijing123
  • 2016年02月24日 11:15
  • 629

Adobe Flash 基本原理

在Adobe flash中, 只要你知道了一下一些概念, 就会发现通过flash 来制作RIA应用是很容易的了。 ...
  • walkingmanc
  • walkingmanc
  • 2011年04月22日 16:40
  • 1813

Flash Player内部机制

1. Flash 运行时用C++、汇编语言和ActionScirpt编写发布的Flash Player版本向前兼容一切归结为核心周期。。。2. 核心周期事件、用户代码、运行时环境和输出相当于Flash...
  • sysu_2010
  • sysu_2010
  • 2011年07月08日 17:39
  • 4424

一个flash日历

一个flash日历,感觉还不错http://download1.csdn.net/down3/20070529/29204709720.swf 
  • libo2006
  • libo2006
  • 2007年05月29日 20:47
  • 635

并行FLASH引导的一点经验-阿哲(转)

最近BBS上关于FLASH和BOOT的讨论很活跃,我也多次来此请教。前几天自制的DSP板引导成功,早就打算写写这方面的东西。我用的 DSP是5416,以其为核心,做了一个相对独立的子系统(硬件、软件、...
  • ydfok
  • ydfok
  • 2007年06月01日 09:06
  • 2263

NOR flash 和NAND flash区别深入分析

闪存芯片读写的基本单位不同     应用程序对NOR芯片操作以“字”为基本单位。为了方便对大容量NOR闪存的管理,通常将NOR闪存分成大小为128KB或者64KB的逻辑块,有时候块内还分成扇区。读...
  • zhangzker
  • zhangzker
  • 2017年04月01日 16:38
  • 1324

flash读写数据

/******************************************************************** 单片...
  • liuxizhen2009
  • liuxizhen2009
  • 2014年10月31日 21:26
  • 799

Flash Socket 的基本通讯协议流程例子

原文:http://www.sujun.org/article.asp?id=51 actionscript3.0 Socket通信实例文章收藏:http://as3.aa-a.net/index....
  • penguin_whl
  • penguin_whl
  • 2012年05月09日 09:30
  • 4551

如何下载浏览器中的flash 视频

首先声明,以下仅供参考,所测试所用视频资源,均为开放视频来源。 也就是说,我测试用的视频,都是任何人都可以看的。都是没有任何权限就可以看的。都是开放的视频。 准备工具,任意浏览器,我这里用的是 谷歌c...
  • u012246342
  • u012246342
  • 2016年09月01日 09:43
  • 10325

Flash芯片的种类与区别

版权声明:本版面文章皆为原创、或参考其他技术网站、博客后自己动手做实验所得,转载请注明出处------028后勤仓库管理员。 一、IIC EEPROM IICEEPROM,采用的是II...
  • lz_kwok
  • lz_kwok
  • 2016年07月26日 08:23
  • 5986
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:The Flash
举报原因:
原因补充:

(最多只允许输入30个字)