Voting

Implementation of the Voting and Rating system.
Ok… Thanks 

Sergio Maziano
smarttechys.co.ao
Cell: +244 992216904



> On Sep 30, 2014, at 10:42 AM, Eliot Sykes <notifications@github.com> wrote:
> 
> In app/controllers/votes_controller.rb:
> 
> > +  end
> > +
> > +  private
> > +
> > +    def load_post_and_vote
> > +        @post = Post.find(params[:post_id])
> > +
> > +        @vote = @post.votes.where(user_id: current_user.id).first
> > +    end
> > +
> > +    def update_vote!(new_value)
> > +      if @vote
> > +        authorize @vote, :update?
> > +        @vote.update_attribute(:value, new_value)
> > +      else
> > +        @vote = current_user.votes.create(value: new_value, post: @post)
> Vote is being created before it's authorized. It'd be good to avoid the vote being created in the db if it fails authorization. See here for usage of current_user.votes.build(...) instead of current_user.votes.create(...)
> 
> Bloc/bloccit-with-tdd@003393d#diff-28572c7c3f75b55711adaebe5c9218c1R22 <https://github.com/Bloc/bloccit-with-tdd/commit/003393ddc31a6f781bc8978b95f9411ef156cfad#diff-28572c7c3f75b55711adaebe5c9218c1R22>
> —
> Reply to this email directly or view it on GitHub <https://github.com/smaziano/bloccit/pull/4/files#r18207589>.
>