gpt4 book ai didi

ruby-on-rails - 在此操作中多次调用渲染和/或重定向。

转载 作者:行者123 更新时间:2023-12-03 16:16:52 25 4
gpt4 key购买 nike

我不断收到 DoubleRenderError,但我不知道为什么!基本上,我有一个 Action 调用另一个 Action 来检查用户输入的查询是否有错误,如果有错误,它会停止并显示错误。但是当我输入一个错误的查询时,当我得到双重渲染时!有什么建议吗?

这是错误检查器操作:

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 /> Should be [IXLSpecClass value][year]-[Message ID] for exam
ple GP07-8)"
redirect_to(:action => "index") and return
end

if !(QueryParser.expression.match(params[:query]))
flash[:error] = %( Format of search criteria is wrong.<br />Should be [IXLSpecClass value][year]-[Message ID] for examp
le GP07-8)
redirect_to(:action => "index") and return
end
yield

以防万一您需要调用此操作的操作..
 def show
if_user_formulated_request_properly do
@statuses = IXLStatus.find(:all)
@input_messages = InputMessage.search_by(params[:query].stri
p) unless params[:query].blank?
@query = params[:query]
end
respond_to do |format|
format.html #default rendering
end
end
end

更新

还忘了提,这最初是一个 rails 2 应用程序并且正在运行,当我升级到 rails 3 时开始出现这个错误(我相信),所以也许 rails 3 与 and return 做了一些不同的事情?

最佳答案

你只是从 if_user_formulated_request_properly 回来方法,这意味着 redirect_torespond_to做一个渲染。

你可以试试这个:

def user_formulated_request_properly?
unless request.post?
flash[:error] = "This page can only be accessed through the search page. (POST request only)"
return false
end

if params[:query].blank?
flash[:error] = "Search criteria can not be blank"
return false
end

if !(params[:query] =~ /-/)
flash[:error] = "( Format of search criteria is wrong.<br /> Should be [IXLSpecClass value][year]-[Message ID] for example GP07-8)"
return false
end

if !(QueryParser.expression.match(params[:query]))
flash[:error] = %( Format of search criteria is wrong.<br />Should be [IXLSpecClass value][year]-[Message ID] for example GP07-8)
return false
end

return true
end


def show
if user_formulated_request_properly?
@statuses = IXLStatus.find(:all)
@input_messages = InputMessage.search_by(params[:query].strip) unless params[:query].blank?
@query = params[:query]
else
redirect_to(:action => "index") and return
end

respond_to do |format|
format.html #default rendering
end
end

关于ruby-on-rails - 在此操作中多次调用渲染和/或重定向。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7260130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com