如果有人在使用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!"
答案 0 :(得分:4)
我遇到了同样的问题,并在服务器日志中看到响应是在JS中。我也在重定向到root_path。
在引用https://stackoverflow.com/a/18681807然后https://stackoverflow.com/a/17689223之后,我解决了我的问题:
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
希望这有帮助!