【问题标题】:Bubble notices through redirects通过重定向气泡通知
【发布时间】:2011-06-14 20:38:59
【问题描述】:

我的场景:

在我的控制器中,确认用户后,我重定向到root(登陆页面:statics#landing)并附上通知:

redirect_to root_url, notice: 'Confirmation successful.'

但在那里,我总是检查用户是否已经登录,如果是,我会将他重定向到实际索引:

def landing
  redirect_to actual_index_url if (user.signed_in?)
end

如何将确认通知传播到最后一页?

【问题讨论】:

    标签: ruby-on-rails-3 redirect controller


    【解决方案1】:

    【讨论】:

    • 这似乎更符合 Rails 习惯:更多细节here
    【解决方案2】:

    试试:

    def landing
      redirect_to actual_index_url, :notice => flash[:notice] if (user.signed_in?)
    end
    

    【讨论】:

      【解决方案3】:

      flash.keep(:notice) - 如果您只想保留通知,只需 flash.keep 将同时保留 :notices:errors

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-04
        • 2021-11-29
        • 2013-06-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多