为什么这种重新指导不起作用?

时间:2014-11-25 16:28:18

标签: ruby-on-rails

控制器

  def subscribe
    @mailchimp_list_id = "01d4743206"
    @gb = Gibbon::API.new
    @email = params[:email]
      @gb.lists.subscribe({
      :id => @mailchimp_list_id,
      :email => @email,
      :double_optin => false,
      :send_welcome => false
    })
    redirect_to root_path, notice: "Whats up"
  end

查看

    <%= form_tag('/posts/subscribe', method: "post", id: "subscribe", remote: "true") do%>
        <div class="large-18 columns text-right mailer">
        <%= email_field(:email, :email, {id: "mailersub", placeholder: "Enter your email"}) %>
        </div>
        <div class="large-6 columns text-right mailer">
            <%= submit_tag("Submit", id: "mailersubmit") %>
        </div>
    <% end %>

我真正希望发生的一切是完成mailchimp进程,然后它会重新指向带有通知的路径。控制器和视图用于邮件列表表单,提交后我希望发生这种情况。

非常感谢任何帮助,谢谢!

2 个答案:

答案 0 :(得分:0)

remote:true执行ajax请求,它无法重定向。你必须删除remote:true或者在js .on ajax:success do location.url ='/'

答案 1 :(得分:0)

这是你的答案,你必须在控制器内部渲染js,内联javascript可用于重定向:

def subscribe
    @mailchimp_list_id = "01d4743206"
    @gb = Gibbon::API.new
    @email = params[:email]
      @gb.lists.subscribe({
      :id => @mailchimp_list_id,
      :email => @email,
      :double_optin => false,
      :send_welcome => false
    })
    flash[:notice] = "Whats up"
    respond_to do |format|
        format.js { render :js => "/" }
    end
  end