使用Redirect_To时,Rails 3 Notices不起作用

CCS*_*Sab 3 session ruby-on-rails authlogic

我有一些代码我有一个:通知,它只是有选择地出现.

这是代码

respond_to do |format|
  if @userhj.save
    format.html { redirect_to(:action => :index, :notice => 'Succesfully assigned job') }
    format.xml  { render :xml => @userhj, :status => :created, :location => @userhj }
  else
    format.html { redirect_to(:root, :notice => 'Duplicate job assignment') }
    format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
  end
end
Run Code Online (Sandbox Code Playgroud)

从:index视图重定向到:index时,通知不会正确显示.看看Firebug的网络控制台,有一个GET(在这里插入网址)?notice =(通知文本),当通知正确显示时,它不会出现在其他页面中.

我正在使用authlogic,只是基本的,使用本教程设置http://www.logansbailey.com/2010/10/06/how-to-setup-authlogic-in-rails-3/.我很感激任何帮助.谢谢.

aNo*_*ble 12

我猜测Ruby认为它:notice是url属性的一部分,而不是options属性.试试这个:

redirect_to({:action => :index}, {:notice => 'Succesfully assigned job'})
Run Code Online (Sandbox Code Playgroud)

  • 哦哇,这完美无缺!不能告诉你这是多么疯狂的驱使我!谢谢! (2认同)