Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3852208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:16:58+00:00 2026-05-19T17:16:58+00:00

I want to make a generic voting controller for lots of different controllers. I’m

  • 0

I want to make a generic voting controller for lots of different controllers.

I’m using the Thumbs_up gem which was formerly the vote_fu gem.

https://github.com/kitop/thumbs_up/blob/master/lib/acts_as_voter.rb

My form looks like so which is a partial with the object @voteable:

<strong class="result">Votes: <%= voteable.votes_for - voteable.votes_against %></strong>

<%= form_tag user_votes_path(current_user) do |f| %>
    <%= radio_button_tag :thumb_direction, :up %>
    <%= radio_button_tag :thumb_direction, :down %>
    <%= hidden_field_tag :voteable, @voteable %>
    <%= submit_tag :vote %>
<% end %>

However when I try passing the voteable object into the controller directly it doesn’t work.

undefined method `base_class’ for
String:Class

My question is then how to polymorphically look up the same object… ie pass the voteable_type and _id instead of the object itself… Unless there is some other easier way?

Controller looks like this

  def create
    #@user = User.find(params[:user_id])
    current_user.vote(params[:voteable], :direction => params[:thumb_direction], :exclusive => true)
  end

#routes

  resources :users do
    resources :votes
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:16:58+00:00Added an answer on May 19, 2026 at 5:16 pm

    Did something like this

      def create
        voteable_class = params[:voteable_type].constantize
        voteable_id = (params[:voteable_type].downcase + "_id").to_sym
        voteable_instance = voteable_class.find(params[voteable_id])
        current_user.vote(voteable_instance, :direction => params[:thumb_direction], :exclusive => true)
        redirect_to :back
      end
    

    And changed my routes for the nested voting resource on each model I wanted to use it.

    erb

    <%= form_tag [voteable, Vote.new] do |f| %>
        <%= radio_button_tag :thumb_direction, :up %>
        <%= radio_button_tag :thumb_direction, :down %>
        <%= hidden_field_tag :voteable_type, voteable.class %>
        <%= submit_tag :vote %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a generic class that accepts only serializable classes, can it
I want to make a login system using ASP.NET (MVC). On the internet, I
I'm starting to consider creating a class library that I want to make generic
I'm implementing the IEditableObject interface and I want to make a generic method that
My table: Users (userID, col1, col2) I want to make a generic stored procedure,
I want to make a FIR filter using a window function. I have some
I want to make a plot in which unit interval on both axes to
I want to make two MySQL records in two different tables and the goal
Hi i want to make a applciation in which the user when open the
I want to make an etag that matches what Apache produces. How does apache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.