在 rails 中使用 gibbon 订阅后添加警报?
Add alert after subscribing with gibbon in rails?
如何在有人使用 Gibbon gem 订阅 Rails 4 中的电子邮件列表后创建提醒?
<%= form_tag('/static_pages/subscribe', method: "post", :class => 'form-inline', id: "subscribe-form", remote: "true",) do %>
<div class='input-group'>
<%= email_field(:email, :address, {id: "email", placeholder: "email address", class: 'btn btn-lg'}) %>
<%= submit_tag(:submit, class: "btn btn-info btn-lg", id: "email-click", 'data-disable-with' => "Please wait...") %>
</div>
<% end %>
这是控制器操作:
def subscribe
@list_id = "43dcea1d12"
gb = Gibbon::API.new
gb.lists.subscribe({
:id => @list_id,
:email => {:email => params[:email][:address]}
})
end
我曾尝试在 gb.lists.subscribe 调用之前或之后添加以下内容,但没有成功
flash[:alert] = "Subscribed!"
我遇到了同样的问题,在服务器日志中看到响应是在 JS 中。我还重定向到 root_path.
参考 and then 后,我解决了我的问题:
respond_to do |format|
format.html {redirect_to root_path}
flash[:alert] = "Subscribed!"
flash.keep(:alert) # Keep flash notice around for the redirect.
format.js {render :js => "window.location.href='"+root_path+"'"}
end
希望对您有所帮助!