Sha256: 8d3e75b46483cd1d46d99eb6097aadbaef394497a2a00f901b8b7284855eb53c

Contents?: true

Size: 542 Bytes

Versions: 6

Compression:

Stored size: 542 Bytes

Contents

class Post < ActiveRecord::Base

  has_many :comments, inverse_of: :post

  after_create :increment_comments_count, :update_last_comment_at, source: :comments
  after_destroy source: :comments do |post|
    post.decrement!(:comments_count)
  end
  before_save do |post|
    post.texts = "#{post.title} #{post.body}".strip.split(/\s+/).join(',')
  end

  private

  def increment_comments_count
    increment!(:comments_count)
  end

  def update_last_comment_at(comment)
    update_attributes!(last_comment_at: comment.created_at)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
association_callbacks-1.0.0 spec/mocks/post.rb
association_callbacks-0.3.0 spec/mocks/post.rb
association_callbacks-0.2.4 spec/mocks/post.rb
association_callbacks-0.2.3 spec/mocks/post.rb
association_callbacks-0.2.2 spec/mocks/post.rb
association_callbacks-0.2.1 spec/mocks/post.rb