如何解决重定向回已不再有效
| 我在将用户重定向到上一页时遇到了麻烦。 这是电影控制器中更新方法的示例。def update
@movie = Movie.find(params[:id])
if @movie.update_attributes(params[:movie])
flash[:notice] = \"The given movie is now updated.\"
end
respond_with(@movie,location: :back)
end
我收到此错误。
respond_with
行上的undefined method \'hash_for_back_url\' for #<Module:0x00000103eeaaa8>
。
我在Ruby 1.9中使用Rails 3.1 rc1。
做这样的事情时,它可以工作。
respond_with(@movie,location: request.referer)
有人知道为什么:back
参数无效吗?
解决方法
对我有用的唯一解决方案是使用
request.referer
。
解决方案1
respond_with(@comment,location: request.referer)
解决方案#2
class ApplicationController < ActionController::Base
helper_method :redirect_back
def redirect_back(options = {})
if request.referer
redirect_to request.referer,options
else
redirect_to root_path,options
end
end
end
# View / controller
redirect_back notice: \"Sending you back ... hopefully\"
,在那种情况下,response_with期望:location是URL帮助方法的结果,如like8ѭ
您可能应该使用以下方法之一:
重定向到带有“ 9”的信息页,相当于“ 10”
使用render :action => :edit
再次使用更新后的数据呈现表单(:edit表示用于显示表单的动作)
,这个怎么样:
respond_with @movie do |format|
format.html { redirect_to :back }
end
使您可以覆盖默认的html响应器,以便可以使用redirect_to :back
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。