當我檢查我的錯誤信息是否正常工作時,我注意到在POST(create
操作)後,我的重定向轉到/businesses
而不是/businesses/new
。我正在使用常規RESTFUL路線,但我需要它在POST時返回/businesses/new
,因爲它們是錯誤的。我怎樣才能做到這一點?創建操作重定向到錯誤的頁面?
這是我當前的代碼:
def create
@business = Business.new(params[:business])
if @business.save
redirect_to :back, :notice => "You have successfully added a new business."
else
render :action => 'new', :notice => "Please try again."
end
end
我的代碼基本上是一樣的。對不起,我沒有包括它。當我編輯我的答案時,您可以查看我的代碼。 – LearningRoR
你確定它通過了else子句嗎? – Chamnap
嗯。看起來實際上並沒有這樣做。我想知道我該如何解決這個錯誤?在POST後它立即停止在'/ business'上。 – LearningRoR