簡體   English   中英

將用戶重定向到注冊頁面-Rails 4?

[英]redirect the users to the sign up page - Rails 4?

我已經構建了一個Rails應用程序。 我已經安裝了Devise for Users注冊並添加了before_action :authenticate_user! 方法,但是此方法的作用是將未注冊用戶重定向到登錄頁面。 我想要的是將他們重定向到注冊頁面,而不是登錄頁面。

這是我的代碼:

rails_course_controller.rb

class RailsCourseController < ApplicationController
  before_action :authenticate_user!


  def railsDashboard
  end

  def getting_started
  end

  def whatisurbyandrails
  end

  def downloadRails
  end

  def windows_download
end

end

您可以覆蓋:authenticate_user!的默認行為:authenticate_user! 方法。 在您的application_controller.rb添加以下內容:

protected
def authenticate_user!
  if user_signed_in?
    super
  else
    redirect_to sign_up_path, :notice => 'Please sign up first'
  end
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM