如何在 rails3 中呈现编辑视图和发布 Flash 消息 [英] How to render edit view and post flash message in rails3

查看:35
本文介绍了如何在 rails3 中呈现编辑视图和发布 Flash 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的帐户控制器中,我想在保存更改并显示 Flash 通知后显示(渲染、重定向到?)编辑视图.

In my account controller I'd like to display (render, redirect_to ?) the edit view after changes get saved and display flash notice.

 def update
    @account = Account.find(params[:id])

    respond_to do |format|
      if @account.update_attributes(params[:account])
        format.html { redirect_to(@account, :notice => 'Account was successfully updated.') }

      else
        format.html { render :action => "edit" }
      end
    end
  end

推荐答案

默认情况下,您必须使用单独的语句,例如

By default you have to use a separate statement, e.g.

format.html { 
  flash[:notice] = 'message'
  render :edit
}

这张票 有一个补丁可以让你使用 render 'edit', :notice =>'消息'.它没有进入 Rails,但有一个 gem,flash_render,添加了它.

This ticket has a patch to let you use render 'edit', :notice => 'message'. It didn't get into Rails but there is a gem, flash_render, that adds it.

这篇关于如何在 rails3 中呈现编辑视图和发布 Flash 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆