Why is :notice not showing after redirect in Rails 3 -
i have following code in controller
def create @tv_show = tvshow.new(params[:tv_show]) respond_to |format| if @tv_show.save format.html { redirect_to(tv_shows_path, :notice => 'tv show created.') } format.xml { render :xml => @tv_show, :status => :created, :location => @tv_show } else format.html { render :action => "new" } format.xml { render :xml => @tv_show.errors, :status => :unprocessable_entity } end end end
and following in tv_shows/index.html.erb
<div id="notice"><%= notice %></div>
but when create new entry notice message not appear after redirect tv_shows_path. have idea why?
is there reason you're trying use :notice
, not flash[:notice]
?
controller:
respond_to |format| if @tv_show.save format.html { flash[:notice] = 'tv show created.' redirect_to tv_shows_path } format.xml { render :xml => @tv_show, :status => :created, :location => @tv_show } else format.html { render :action => "new" } format.xml { render :xml => @tv_show.errors, :status => :unprocessable_entity } end end
view:
<% if flash[:notice] %> <div id="notice"><%= flash[:notice] %></div> <% end %>
Comments
Post a Comment