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

  • Home
  • SEARCH
  • 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 4259994
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:51:38+00:00 2026-05-21T05:51:38+00:00

I am using the Thumb_Up gem for ruby on rails. https://github.com/brady8/thumbs_up I want users

  • 0

I am using the Thumb_Up gem for ruby on rails.
https://github.com/brady8/thumbs_up

I want users to be able to vote on posts.
However, I am unable to figure out how I can allow a user to click a button next to each post and add a vote to the database.

I can get this to happen in the rails console through doing the following:

u=User.first

m=Micropost.first

u.vote_for(m)

However, how can I get this to happen when a button is clicked in view. I am assuming I would have to use ajax, but how would I know the url I need to post to to make this action occur?

Any help would be greatly appreciated.

Update:

Thanks so much for the help! I am still having a problem with the code below.

Here is my routes.rb

resources :microposts do
  post :vote, :on => :member
end

View:

<%= link_to('vote for this post!', vote_micropost_path(@micropost), :method => :post) %>

Controller:

def vote
    @micropost = Micropost.find(params[:id])
  current_user.vote_for @micropost

  # This assumes you'll only call it via AJAX.
  # If your ajax call doesn't return "ok", then you know something went wrong
  render :text => 'ok', :layout => false
end

However, I’m still getting this error:
No route matches {:controller=>”microposts”, :id=>#, :action=>”vote”}

Would anyone know why the routes aren’t matching correctly?

  • 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-21T05:51:39+00:00Added an answer on May 21, 2026 at 5:51 am

    I am assuming Rails 3. Rails 2’s routes would look a little different.

    First you would need to define a route in your config/routes.rb file. You could do this many ways. If you already have a route for microposts, you could simply add a “vote” action:

        resources :microposts do
          post :vote, :on => :member
        end
    

    (For clarity, the “post” above refers to the HTTP POST method and has nothing to do with your Micropost class.) If you use that route, you would then need to create a “vote” method in your Microposts controller to catch it. Something like

        def vote
          @post = Micropost.find(params[:id])
          current_user.vote_for @post
    
          # This assumes you'll only call it via AJAX.
          # If your ajax call doesn't return "ok", then you know something went wrong
          render :text => 'ok', :layout => false
        end
    

    Then in your view’s AJAX POST call (assuming the example route I gave), you would get the url with:

        vote_micropost_path(@micropost)
    

    It would look like /microposts/56/vote

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Paperclip with a Ruby on Rails to attach assets to a model,
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
Using JDeveloper , I started developing a set of web pages for a project
Using C#, I need a class called User that has a username, password, active

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.