Voting

Allow for AJAXy voting on comments and articles. Resolves #14.


![](http://zippy.gfycat.com/ImpracticalPastCardinal.gif)
I noticed some duplication in some of the code above, so I took a stab at refactoring. Thoughts?

```ruby
class VotesController < ApplicationController
  def up
    update_vote(:up)
  end

  def down
    update_vote(:down)
  end


  private

  def update_vote(direction)
    if vote.send("#{direction}?")
      response_for(:destroy)
    else
      vote.is_up = direction == :up
      response_for(:save)
    end
  end

  def response_for(action)
    format.js do
      if vote.send(action)
        render template: 'votes/vote'
      else
        render status: :unprocessable_entity
      end
    end
  end
end


class Vote < ActiveRecord::Base
  def up?
    is_up?
  end

  def down?
    !up?
  end
end
```