[Rails]activeadmin skip authentication check

如何跳過會員驗證進入activeadmin後台

1.把下面的code複製到controller的block裡(activeadmin register file)

 def self.filters(kind = nil)
    all_filters = _process_action_callbacks
    all_filters = all_filters.select{|f| f.kind == kind} if kind
    all_filters.map(&:filter)
  end

  def self.before_filters
    filters(:before)
  end

  def self.after_filters
    filters(:after)
  end

  def self.around_filters
    filters(:around)
  end

2.在上面這些method的後面下 binding.pry,重整頁面進到debug模式下然後輸入 filters(:before) 這樣就可以看到在before_filters的時候會呼叫到哪些callback,找有關鍵字 authentication 的callback ex: authenticate_active_admin_user
3.在controller裡的最上面加上 skip_before_filter :authenticate_active_admin_user ,這樣就可以跳過會員登入直接看到admin後台的某個頁面。
參考資料:http://stackoverflow.com/a/31077978

comments powered by Disqus