Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render edit view and post flash message in rails3

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 
like image 831
Olivier Avatar asked Jan 22 '11 21:01

Olivier


1 Answers

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

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

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.

like image 63
Brian Deterling Avatar answered Sep 28 '22 23:09

Brian Deterling