我不斷收到DoubleRenderError,我找不出原因!基本上,我有一個操作,調用另一個操作來檢查用戶輸入的查詢是否有錯誤,如果錯誤發生,它會停止並顯示錯誤。但是,當我輸入一個錯誤的查詢,當我得到雙渲染!任何建議?渲染和/或重定向在這個動作中被多次調用..?
繼承人的錯誤檢查動作:
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
UPDATE
也忘了提,這最初是一個軌道2應用程序和工作,這個錯誤開始時,我升級到軌道3(我相信),所以也許軌道3做一些與and return
有什麼不同?
它無論哪個動作是第一?因爲離開我原來的訂單和你的修改,我得到'未定義的方法'if_user_formulated_request_properly'' –
我改變了方法的名稱使其更清晰,現在它是'user_formulated_request_properly?'。 –
應該已經能夠糾正你自己:)反正工作完美..謝謝一堆 –