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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:09:05+00:00 2026-05-30T06:09:05+00:00

The app allows users to vote on embedded videos. When users click up and

  • 0

The app allows users to vote on embedded videos. When users click up and down arrows, the whole page refreshes to update points. I have been attempting to implement AJAX voting for months now. I would like the most straightforward solution you can offer, even if it isn’t the most efficient. Any ideas?

My up and down actions from app/controllers/links_controller

  ....

  def up
    @link = Link.find(params[:id])
    @link.update_attribute :points, @link.points + 1
    redirect_to :back 
  end

  def down 
    @link = Link.find(params[:id])
    @link.update_attribute :points, @link.points - 1
    redirect_to :back 
  end 

  ....

A minimalist version of links_list, a partial from app/views/links/_links_list, which I render in other views using various sorting methods

  <% @links.each do |link| %>
        <div class="row">
            <div class="span2">
                <%= link_to (image_tag ("up.png")), up_link_url(link), :method => :put %> 
                <%= link.points %>
                <%= link_to (image_tag ("down.png")), down_link_url(link), :method => :put %>
            </div>
            <div class="span8">
                <%= link_to strip_tags(link.title), link %> 
            </div>
        </div>
  <% end %>
  • I would like to achieve this without use of an external gem, the app is already in production
  • I have probably seen and tried most rails 3 tutorials related to ajax and rails. If you post a link to a tutorial, please suggest mods that would need to take place for it to work.
  • I’m running Rails 3.1

Thanks in advance for any feedback or suggestions!

  • 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-30T06:09:07+00:00Added an answer on May 30, 2026 at 6:09 am

    Ajax is pretty easy to use in Rails 3.1. This post assumes you’re using jQuery as your JavaScript driver; if you aren’t, you’ll need to install the jquery-rails gem, but even for an app in production adding a small gem shouldn’t be a really big deal.

    Your controller will end up looking like this:

    ....
    
    def up
      @link = Link.find(params[:id])
      @link.update_attribute :points, @link.points + 1
      respond_to do |format|
        format.html {redirect_to :back}
        format.js
      end
    end
    
    def down 
      @link = Link.find(params[:id])
      @link.update_attribute :points, @link.points - 1
      respond_to do |format|
        format.html {redirect_to :back}
        format.js
      end
    end 
    
    ....
    

    The view change will be pretty small:

    <% @links.each do |link| %>
      <div class="row">
        <div class="span2">
          <%= link_to (image_tag ("up.png")), up_link_url(link), :method => :put, :remote => true %> 
          <%= link.points %>
          <%= link_to (image_tag ("down.png")), down_link_url(link), :method => :put, :remote => true %>
         </div>
         <div class="span8">
           <%= link_to strip_tags(link.title), link %> 
         </div>
      </div>
    

    And you’ll need new files, up.js.erb and down.js.erb, in your app/views/links/ folder, which contains the JavaScript command to update your page:

    $(".span2").html("This post has <%= @link.points %> points.")
    

    If you decide to go with Prototype or something the code will look more or less the same; the only change will be the JavaScript you place in up.js.erb and down.js.erb, which should be Prototype-y instead of jQuery-y.

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

Sidebar

Related Questions

I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have an existing web app that allows users to rate items based on
We have a WPF app that allows our users to download encrypted content and
My app allows users to have custom subdomains, as in user1.domain.com. I am integrating
I have developed a small web app. This app allows users to upload images.
We have an app that allows users to send e-mails from our system. It
I have a Silveright app that allows users to specify filters on a few
I have a Rails app that allows users to build up a network structure
I have an app that allows users to generate objects, and store them (in

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.