title: Voting in voter controller for multiple models passing polymorphic/duck typed object variable
body: <p>I am trying to implement voting for various models: Character, Universe models. I have some vote buttons on their respective show templates via a single DRY rendered partial. This means I need to make that partial agnostic to the model when I pass that model to the controller logic that creates the vote record.</p>
  
  <p>So yes, I am wondering if it is possible to have this kind of duck typed variable passing to a votes controller, rather than repeating the vote creation logic in each of the Character and Universe controller.</p>
  
  <p>How do I make this sort of duck typed variable passing using path helpers, votes partials, and votes controllers? Or should I just repeat the code in each votable model?</p>
  
  <p>FYI: Naturally, the votes is polymorphic to the two models. I am using acts_as_votable gem <a href="https://github.com/ryanto/acts_as_votable" rel="nofollow">https://github.com/ryanto/acts_as_votable</a></p>
  
  <p><strong><em>_vote.html.haml</em></strong></p>
  
  <pre><code>.vote-comment-buttons
    = link_to image_tag("upvote.png"), votes_upvote_path(), method: :post, remote: true
    %span=# @comment.get_upvotes.sum(:vote_weight)
    = link_to image_tag("downvote.png"), votes_downvote_path(), method: :post, remote: true
  </code></pre>
  
  <p>^ Do I pass a duck type variable to the paths?, If so, how/where do I define the duck type variable?</p>
  
  <p>(Note: i'm trying to vote via AJAX, but feel free to ignore the ajax related code like remote: true)</p>
  
  <p><strong>character.rb</strong></p>
  
  <pre><code>class Character &lt; ActiveRecord::Base
    acts_as_votable # creates a polymorphic association with votes
  end
  </code></pre>
  
  <p><strong>universe.rb</strong></p>
  
  <pre><code>class Universe &lt; ActiveRecord::Base
    acts_as_votable # creates a polymorphic association with votes
  end
  </code></pre>
  
  <p><strong>votes_controller.rb</strong></p>
  
  <pre><code>class VotesController &lt; ApplicationController
  
    before_action :check_if_voted(@votable)
  
    def upvote
      #votable.vote_up current_user
  
    end
  
    def downvote(votable)
      #votable.vote_down current_user
    end
  end
  </code></pre>
  
  <p>Iis it valid to have parameters on actions? or do you just use params[]?</p>