我有一个Rails 4应用程序,我在控制器内部有一个动作,我的routes.rb将路由映射为一个帖子请求。
post '/contact', :to => "page#contact_email"
在我的page_controller.rb里面我有
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
使用发送电子邮件所需的表单数据发布到此网址后,页面静止不动,而我可以在控制台中看到它成功发送电子邮件,并重定向到&#39; /&#39; < / p>
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)
然而,我的网页静止不动,无所事事。
有什么想法吗?
答案 0 :(得分:2)
由于您似乎正在进行异步发布,请尝试替换:
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}'"
或类似的东西。
答案 1 :(得分:0)
替换
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"
redirect_to root_path