所以我试图在这里采取正确的路径并了解如何解决这个警察,在我看来这看起来像是一小段代码,为什么它会抱怨?
移动嵌套的 if-else 不会改变任何东西,关于如何解决这个警察有什么建议吗?
class WebPush::Register
include Interactor
# rubocop:disable Metrics/AbcSize
def call
user = Learner.find_by(id: context.user_id)
# return if existing
if user.web_push_subscription
context.subscription = user.web_push_subscription
else
subscription = WebPushSubscription.new(
endpoint: context.push_params[:endpoint],
auth_key: context.push_params[:keys][:auth],
p256dh_key: context.push_params[:keys][:p256dh],
learner: user
)
if subscription.save
context.subscription = subscription
else
context.error = subscription.errors.full_messages
context.fail!
end
end
end
# rubocop:enable Metrics/AbcSize
end
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 papertrail 将模型的更改事件记录在单独的数据库中。
我正在使用 Rails 4.1.2
红宝石2.1
纸迹 4.0.0
下面是我在关注中添加的代码
module Foo
class Base < ActiveRecord::Base
end
class Version < Base
include PaperTrail::VersionConcern
end
class Topic < Base
has_paper_trail class_name: 'Foo::Version'
end
end
Foo::Base.establish_connection(:trail_development)
Run Code Online (Sandbox Code Playgroud)
我已将这个 Foo 包含在 topic.rb 中
class Topic < ActiveRecord::Base
include Foo
end
Run Code Online (Sandbox Code Playgroud)
当我尝试创建、编辑或删除主题时,这不起作用。