我有一个rails 4应用程序,在控制器中有一个动作,我的routes.rb将一个路由映射为post请求。
post '/contact', :to => "page#contact_email"
我的页面控制器里有
def contact_email
mail = UserMailer.contact_email(params).deliver
redirect_to root_url, notice: "Thank you for contacting us! We'll be in touch shortly"
end
在将发送电子邮件所需的表单数据发布到此url后,页面静止不动,而我可以在控制台中看到它成功地发送了电子邮件,并将重定向到“/”
Started GET "/" for 127.0.0.1 at 2014-10-21 19:42:34 -0700
Processing by ApplicationController#home as */*
Completed 200 OK in 792ms (Views: 780.6ms | ActiveRecord: 7.8ms)
然而,我的网页一动不动,什么也不做。
有什么想法吗?
最佳答案
因为看起来您正在执行异步POST,所以请尝试替换:
redirect_to root_url notice: "Thank you for contacting us! We'll be in touch shortly"
具有
flash[:notice] = "Thank you for contacting us! We'll be in touch shortly"
render js: "window.location = '#{root_path}'"
或者类似的东西。