我正在尝试在提交电子邮件订阅表单后重定向到页面。订阅工作正常,但页面不重定向。
这就是我在控制器中的内容
class EmailapiController < ApplicationController
def index
end
def subscribe
@list_id = "alistid"
gb = Gibbon::API.new
gb.lists.subscribe({
:id => @list_id,
:email => {:email => params[:email][:address]},
:double_opt_in => false
})
flash[:success] = "Thank You for Subscribing"
respond_to do |format|
format.html { redirect_to "http://www.rubyonrails.org" }
#format.js
end
end
end
我的表单看起来像这样
<%= form_tag('emailapi/subscribe', method: "post", id: "subscribe", remote: "true", class: "form-inline" ) do -%>
<%= email_field(:email, :address, {id: "email", placeholder: "Enter your email..."}) %>
<%= submit_tag("Notify Me", class: "submit-btn", id: "submit-btn" ) %>
<% end %>
并且在routes.rb中我有:
post 'emailapi/subscribe' => 'emailapi#subscribe'
由于
答案 0 :(得分:0)
您正在使用远程表单,但未处理js响应。创建一个视图subscribe.js.erb
并将其放入其中window.location = "http://www.rubyonrails.org";