2016-12-21 3 views
2

通知を取得するために公開アクティビティを使用しています。私は祈りのモデルで新しい祈りを追跡しています。何らかの理由で、私がPainを削除したときにcurrent_userがnilになってしまい、理由を理解できません。Rails - Current_userは、痛みを削除するときにはnilです。

class Prayer < ApplicationRecord 
include PublicActivity::Model 

    has_many :activities, as: :trackable, class_name: 'PublicActivity::Activity', dependent: :destroy 
    tracked owner: Proc.new { |controller, model| controller.current_user } #fail current_user is nil 
end 

class Pain < ApplicationRecord 
belongs_to :user 
has_many :prayers, dependent: :destroy 
end 

私はより多くのコードを提供することができますが、何が役立つかはわかりません。 どうもありがとう

編集:私はEDIT2

Railsの管理ページで、私は痛みを削除しようとしていると言うのを忘れ:Railsの管理者設定

RailsAdmin.config do |config| 

config.actions do 
    dashboard      # mandatory 
    index       # mandatory 
    new 
    export 
    bulk_delete 
    show 
    edit 
    delete 
    show_in_app 
end 

config.authorize_with do |controller| 
    redirect_to main_app.root_path unless current_user && current_user.admin 
end 
end 
+0

あなたはログインしていませんか?したがって、現在のユーザーはいません。 –

+0

私はRailsの管理ページでPainを削除しようとしているのを忘れていました – Ayter

+0

あなたのRails Adminの設定を表示できますか? – Thanh

答えて

0

[OK]を私は、解決策を見つけました私のApplicationControllerで私はhelper_methodを呼び出します:current_user

class ApplicationController < ActionController::Base 
    helper_method :current_user 

    def current_user 
    @current_user ||= User.find_by(id: session[:user]) 
    end 
end 

私は祈りモデルでcurrent_userにアクセスできます。

全員ありがとう

関連する問題