本文介绍了使用 Redirect_To 时,Rails 3 通知不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,我有一个 :notice,它只是有选择地显示.

I've got some code I have a :notice, which is only showing up selectively.

这是代码

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

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

When redirecting to :index from the :index view, the notices don't show up properly. Taking a look at Firebug's net console, there's a GET (insert url here)?notice=(notice text), which doesn't appear in other pages when the notices do show up correctly.

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

I'm using authlogic, just basic, set up using this tutorial http://www.logansbailey.com/2010/10/06/how-to-setup-authlogic-in-rails-3/. I'd appreciate any help with this. Thanks.

推荐答案

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

I'm guessing that Ruby is thinking that :notice is part of the url attribute rather than the options attribute. Try this:

redirect_to({:action => :index}, {:notice => 'Succesfully assigned job'})

这篇关于使用 Redirect_To 时,Rails 3 通知不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:32