小编act*_*ars的帖子

为什么会出现双重渲染错误?

在我的rails应用程序中我突然得到一个双重渲染错误(Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at mos ....etc...),我不能为我的生活弄清楚双渲染的位置.当用户输入的查询格式不正确时,就会出现这种情况.以下是检查格式并显示错误的代码:

 def if_user_formulated_request_properly
    unless request.post?
      flash[:error] = "This page can only be accessed through the search page. (POST request only)"
      redirect_to(:action => "index") and return
    end
    if params[:query].blank?
      flash[:error] = "Search criteria can not be blank"
      redirect_to(:action => "index") and return
    end
    if !(params[:query] =~ /-/)
      flash[:error] = %( Format of search criteria is wrong.<br …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

3
推荐指数
1
解决办法
8070
查看次数

标签 统计

ruby-on-rails ×1