Skip to content

Instantly share code, notes, and snippets.

@leepfrog
Last active December 14, 2015 19:59
Show Gist options
  • Save leepfrog/5140428 to your computer and use it in GitHub Desktop.
Save leepfrog/5140428 to your computer and use it in GitHub Desktop.
class VotesController < ApplicationController
  def create
    @vote = Vote.find_or_initialize_by_submitted_by_ip(request.remote_ip)
    @vote.update_attributes(params[:vote]) if !@vote.has_user?(session[:user_id])
    render json: @vote
  end
end

class Vote < ActiveRecord::Base
  def has_user?(uid)
    self.user_id.eql?(uid)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment