【发布时间】:2016-12-21 11:04:35
【问题描述】:
我正在使用公共活动来获取通知。我正在我的祷告模型中跟踪新的祷告。出于某种原因,当我删除 Pain 时 current_user 为零,我不明白为什么。
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
我可以提供更多代码,但我不确定什么会有用。 非常感谢
编辑:我忘了说我正在尝试删除 Rails 管理页面中的 Pain
Edit2: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
【问题讨论】:
-
你没有登录,我猜?因此,没有当前用户。
-
我忘了说我正在尝试删除 Rails 管理页面中的 Pain
-
你能展示一下你的 Rails Admin 配置吗?
-
好的,我已经编辑了我的帖子
标签: ruby-on-rails devise public-activity