我的控制器中有以下代码
- 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
和我的tv_shows / index.html.erb中的以下内容
- <div id="notice"><%= notice %></div>
解决方法
有什么理由你试图使用:通知而不是闪光[:通知]?
控制器:
- respond_to do |format|
- if @tv_show.save
- format.html {
- flash[:notice] = 'Tv show was successfully created.'
- redirect_to tv_shows_path
- }
- format.xml { render :xml => @tv_show,:location => @tv_show }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @tv_show.errors,:status => :unprocessable_entity }
- end
- end
视图:
- <% if flash[:notice] %>
- <div id="notice"><%= flash[:notice] %></div>
- <% end %>