The Flash

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
时间: 2024-10-28 10:33:53

The Flash的相关文章

使用华邦的SPI FLASH作为EPCS时固化NIOS II软件报错及解决方案

Altera器件有EPCS系列配置器件,其实,这些配置器件就是我们平时通用的SPIFlash,据AlteraFAE描述:"EPCS器件也是选用某家公司的SPIFlash,只是中间经过Altera公司的严格测试,所以稳定性及耐用性都超过通用的SPIFlash".就本人看来,半导体的稳定性问题绝大部分都是由本身设计缺陷造成的,而成熟的制造工艺不会造成产品的不稳定:并且,现在Altera的器件在读入配置数据发生错误时,可以重新读取SPIFlash里面的数据,所以在工艺的稳定性以及设计的可靠性

Install Adobe Flash Player 11.2 on CentOS/RHEL 7/6/5, Fedora 20/19

Adobe Flash Player are very useful for watching videos in web browser online. Without flash player most of the videos will not play in your browser. This article will help you to install Adobe flash player plugin for your browsers in CentOS 6/5, Redh

CentOS 7 Install Adobe Flash Player

From Officail Adobe Flash Site don't down (YUM )adobe-release-x86_64-1.0-1.noarch.rpm,but to download RPM(flash-plugin-11.2.202.621-release.x86_64.rpm) If you use SELinux, you will get a warn.Following the warn do the suggestion steps.It's OK! SELinu

(转)RAM、ROM、SRAM、DRAM、SSRAM、SDRAM、FLASH、EEPROM的区别

RAM(Random Access Memory) 随机存储器.存储单元的内容可按需随意取出或存入,且存取的速度与存储单元的位置无关的存储器.这种存储器在断电时将丢失其存储内容,故主要用于存储短时间使用的程序. 按照存储信息的不同,随机存储器又分为静态随机存储器(Static RAM,SRAM)和动态随机存储器(Dynamic RAM,DRAM). ROM(Read-Only Memory)只读存储器,是一种只能读出事先所存数据的固态半导体存储器.其特性是一旦储存资料就无法再将之改变或删除.通常

企业形象网站-------------flash全站系统

该网站使用Photoshop与Illustrator进行页面设计,使用Dreamweaver进行网页制作,使用3dsmax与 AfterEffects进行三维动画制作,使用Flash进行全部交互功能制作.

MFC里创建FLASH控件,并从内存流中载入SWF

#include <atlbase.h> extern CComModule _Module;      #include <atlcom.h> #include <oleacc.h> #include <comdef.h> #pragma comment(lib,"atl") #pragma comment(lib,"User32.lib") #import "c:\WINDOWS\system32\Mac

Flash的选择

算起来自己接触Flash接近4年了. 最开始的2.0,做按钮,做动画,做导航. 后来用3.0做动画,做相册,做毕业设计,做课件. 然后到公司做2.0的动画,模板开发,效果设计. 似乎又回到了原点. 个人是喜欢做flash相关的东西的,就像我一样喜欢设计创意. 而看到别人用上自己的作品,心中是很高兴与自豪的. 这个行业都在不停的交融淘汰. 我得找到新的方向. 选择一:游戏 选择二:3D特效. 选择三:人物动画. 对游戏开发不太感冒,故而选择3D. 加油. 版权声明:本文为博主原创文章,未经博主允许

一个Flash开发者从入门到放弃的成长之路

本文将按照入门.成长.转行三个关键词来讲述作者这些年使用Flash进行项目开发的整个历史过程. 一.入门--开始走上Flash的道路. 和Flash的机缘要从大学时代说起.2005年下半年,学校开设了网页三剑客,就是DreamWeaver.Fireworks.Flash三个软件.在那个课程之前,各种课程都是偏理论的课程,比如C.数据库原理.线性代数,这些课程学着都比较枯燥,而这个网页三剑客课程这是实践性非常强,可以做网站.动画之类的.我对这些自然也有很大的兴趣,那时候自己刚刚买了电脑,课间之余,

Flash自适应舞台和对齐处理

普通应用: import flash.display.StageAlign; import flash.display.StageScaleMode; stage.align=StageAlign.TOP_LEFT; stage.scaleMode="noScale"; stage.addEventListener(Event.RESIZE,resizeHandler); function resizeHandler(event:Event) { bj.width=stage.stag

Linux下Chromium使用flash的办法

环境说明: 系统:  CentOS 6.5 X64 很简单,主要原因是在启动Chromium的时候指定了自有的Flash,我们可以在启动参数上去除指定的Flash! sudo vim  /usr/bin/chromium-browser CHROMIUM_RHEL_FLAGS="--enable-plugins --enable-extensions --enable-user-scripts --enable-printing --enable-sync --auto-ssl-client-a