title: Refactoring controller actions
body: <p>For example: </p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    belongs_to :article
  end 
  
  class Article &lt; ActiveRecord::Base
    has_many :posts
  end
  </code></pre>
  
  <p>I need change status in article, when I delete last post or change article to nil in last post, I have two actions with common logic:</p>
  
  <pre><code>  def destroy
      post = Post.find(params[:id])
      article = post.article
      post.destroy
      if article &amp;&amp; !article.posts.present?
        if article.status == 2 
          article.status = 1
          article.save
          notice = " and it was last post for article #{article.title} and article status change to empty!"
        end
      end
      redirect_to(posts_path(:by_status=&gt;:all), :notice =&gt; "Post was successfully deleted #{notice}")
    end
  
    def remove_from_article
      post = Post.find(params[:id])
      article = post.article
      post.article = nil
      post.save
      if article &amp;&amp; !article.posts.present?
        if article.status == 2 
          article.status = 1
          article.save
          notice = " and it was last post for article #{article.title} and article status change to empty!"
        end
      end
      redirect_to(posts_path(:by_status=&gt;:all), :notice =&gt; "Post was successfully updated #{notice}")
    end
  </code></pre>
  
  <p>How can I refactoring this code, should I use after or around filter, if yes how can I pass article to it? </p>