title: voting system for rails blog with devise user login before voting
body: <p>So I have a blog I am trying to have a simple upvote/downvote feature for the posts. I have devise set up and I made all the associations between the models,  votings, users, and home_blogs. </p>
  
  <pre><code>class User &lt; ApplicationRecord
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
    has_many :liked_home_blogs, through: :votings
  end
  
  class HomeBlog &lt; ApplicationRecord
    mount_uploader :image, ImageUploader
    has_many :hashtaggings
    has_many :hashtags, through: :hashtaggings
    has_many :votings
    has_many :votants, through: :votings
  
    def all_hashes=(names)
      self.hashtags = names.split(",").map do |name|
        Hashtag.where(name: name.strip).first_or_create!
      end
    end
  
    def all_hashes
      self.hashtags.map(&amp;:name).join(", ")
    end
  end
  
  class Voting &lt; ApplicationRecord
    belongs_to :home_blog
    belongs_to :user 
  end
  </code></pre>
  
  <p>and the controller looks like this at the moment: </p>
  
  <pre><code>class VotingsController &lt; ApplicationController
  
    before_action :authenticate_user!
  
  def upvote
      @votings = HomeBlog.find(params[:home_blog_id])
      @votings.votings.build( :upvote =&gt; true, :downvote =&gt; false, 
  :user_id =&gt; current_user.id)
      @votings.save!
        redirect_to request.referrer, notice: "Thanks for the 
   vote!"
   end
  
  
  
       def downvote
          @voting = HomeBlog.find(params[:home_blog_id])
          @voting.votings.build( :downvote =&gt; true, :upvote =&gt; 
      false, :user_id =&gt; current_user.id)
          @voting.save!
            redirect_to request.referrer, notice: "Thanks for the 
      vote!"
        end
  private 
  
  def voting_params
            params.require(:voting).permit(:upvote, :downvote, 
       :home_blog_id, :user_id)
   end
  
  end
  </code></pre>
  
  <p>Sorry about the crappy copy and paste for the controller. My question is, how do I make a condition for the current_user in devise to limit them to one vote per home_blog post? Thanks! </p>