I have the following code in my controller
def create
@tv_show = TvShow.new(params[:tv_show])
respond_to do |format|
if @tv_show.save
format.html { redirect_to(tv_shows_path, :notice => 'Tv show was successfully 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 the following in my tv_shows/index.html.erb
<div id="notice"><%= notice %></div>
but when I create a new entry the notice message does not appear after the redirect to tv_shows_path. Have anyone an idea why?
I just had the same issue and the error was so silly but sometimes unnotable.
I have in my application layout the following code:
Now, can you see why I was unable to see my flash message?
Yup! You should check if you put the
=
sign here:Is there any reason you're trying to use
:notice
and notflash[:notice]
?Controller:
View:
The reason why the code didn't work was a problem with my authentication code... After I implemented my new way of authentication from scratch the code above is working.
I encountered similar 'problem' and the cause was that I was redirecting to action that in itself had another redirection. In the above case the most probable cause was that within
tv_shows_path
another redirection exists.In my case I had something like this in a filter:
And
root_url
was set to point tohome#index
:This second redirect_to was causing my 'unauthorized_access' notice not to show up.
The solution is to simply redirect to
customers_path
immediately and not toroot_url
. Hope this helps someone.