rails-engine / notifications

🛎 Notifications Center engine like GitHub or other application for any Rails applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

will_paginate 很怪的依赖

lufeihaidao opened this issue · comments

#2 提出了will_paginate,除此之外,还有 puma mysql2 bootstrap,看不明白为什么需要这些 gem。严格来说,devise 都不应该依赖。但是考虑到这种场景,依赖也无所谓。上面四个确实想不明白,这种依赖,基本没办法让别人通用了。

这个东西的设计是针对这类场景,上去就能用,我不在乎其他不用这类库的项目是否能用(其实是能用的 Devise 不是需要的,Gem 也没有依赖 Devise,而是设计了类似的接口,Bootstrap 也不是必要的,你看到的那是测试代码里面有),解决的目的是针对这一套

在 rails-engine 这个组里面所有的 Gem 实现思路都是这样的

还有个小问题,

class Comment
  belongs_to :post
  belongs_user :user

  after_commit :create_notifications, on: [:create]
  def create_notifications
    Notification.create(
      notify_type: 'comment',
      actor: self.user,
      user: self.post.user,
      target: self)
  end
end

这段代码中,如果 current_user == self.post.user,意味着我在我的帖子里回复,也会给自己发通知,但是在 ruby-china 上似乎并没有发生这种情况。是如何实现的呢?我搜了些答案,都表示不建议在 model 中获取 current_user

actor = user 的时候排除掉就好了

实际上 will_paginate 这种方式完全可以 Kaminari 共存的。

我已经测试过。