这是我的 after_create 回调:
after_create { |f| if f.target.class.eql?(Question)
if f.target.user != User.current_user
Notify.create_notify( Notify::QUESTION_FOLLOW, f.target.user, User.current_user, f.target)
end
elsif f.target.class.eql?(User)
Notify.create_notify( Notify::USER_FOLLOW, f.target, User.current_user,f.target) if f.target.can_mail_user(:follower)
end
}
我尝试将它移动到一个块中,所以现在它如下所示:
after_create do |f|
if f.target.class.eql?(Question)
if f.target.user != User.current_user
Notify.create_notify( Notify::QUESTION_FOLLOW, f.target.user, User.current_user, f.target)
end
elsif f.target.class.eql?(User)
Notify.create_notify( Notify::USER_FOLLOW, f.target, User.current_user,f.target) if f.target.can_mail_user(:follower)
end
end
我还能做些什么来改进该代码?