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 7409391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:04:36+00:00 2026-05-29T06:04:36+00:00

I built a simple voting system: votes_controller.rb: class VotesController < ApplicationController def vote_up @post

  • 0

I built a simple voting system:

votes_controller.rb:

class VotesController < ApplicationController
  def vote_up
    @post = Post.find(params[:id])
    @vote = @post.votes.create(:user_id => current_user.id, :polarity => 1)
  end
end

(If there is any bad practice here, please let me know)

views/show.html.erb:

<h3><%= @post.votes.count %> votes</h3><br />

<%= link_to "Vote Up", vote_up_path(@post), :remote => true %>

(I will put this in a partial of course)

routes.rb:

get 'votes/:id/vote_up' => 'votes#vote_up', as: 'vote_up'

When I click the “Vote Up” link the vote is added to the post but I have to refresh the page in order to see the changes. How can I refresh @post.votes.count and vote.user.username dynamically with Ajax/JavaScript?

  • 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-29T06:04:36+00:00Added an answer on May 29, 2026 at 6:04 am

    First put make a wrapper div for show.html.erb

    <div class='post-<%=@post.id%>' >
     <h3><%= @post.votes.count %> votes</h3><br />
     <%= link_to "Vote Up", vote_up_path(@post), :remote => true %>
    </div>
    

    and in vote_up.js.erb

    $("post-<%=@post.id%>").html('<%=escape_javascript @post.votes.count %>');
    

    or something like this

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

Sidebar

Related Questions

I found this tutorial about how to build a simple voting system. I already
Hello I've built a simple packet skeleton where each packet is a class file
I built a simple website which allows users to post their profiles, classifieds and
I built a simple social community website for a client - the client would
I have built a simple C#.Net app on a M/C with only .Net FX
I've built a simple application that applies grid-lines to an image or just simple
I have built a simple Eclipse plugin where a user may use a TableViewer
I have built a simple menu in jQuery http://vanquish.websitewelcome.com/~toberua/ Here is a sample of
I've built a simple cms with an admin section. I want to create something
Having read Joe Armstrong's book and watched Kevin Smith screencasts I've built a simple

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.