我在rails中保存類別。如果保存成功與msg =成功,並希望傳遞消息,它就會起作用。但是,如果包含多個單詞消息,例如msg =類別已成功保存,或者msg ='類別已成功保存類別「,則說明錯誤URI存在錯誤。如何在URL中包含多字字符串redirect_to
下面的代碼工作:
if @category.save!
redirect_to "/view_handler?index=1&msg=successfully&url=#{categories_path}"
else
render :action => "new"
end
但是這不,用單引號或不:
if @category.save!
redirect_to "/view_handler?index=1&msg=category saved successfully&url=#{categories_path}"
else
render :action => "new"
end
這裏是view_handler代碼:
def view_handler
index = params[:index].to_i
url = params[:url]
msg = params[:msg]
if index == 0 #backword
session[:page_step] -= 1 #step_back
url = session[('page' + session[:page_step].to_s).to_sym]
else #forward
session[:page_step] += 1
session[('page' + session[:page_step].to_s).to_sym] = url
end
#redirect to the page by url
if msg.nil?
redirect_to url
else
redirect_to url, :notice => msg
end
end
任何關於錯誤的想法?謝謝。