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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:44:18+00:00 2026-05-16T18:44:18+00:00

I want to implement a like-counter on an object. Everytime the ‘I like’ Button

  • 0

I want to implement a like-counter on an object. Everytime the ‘I like’ Button gets clicked I want to update the database-field of the object.

In the controllers show-view I placed following form:

<% form_for(@book) do |f| %>
 <p>
  <% @book.update_like(@book)%>
  <%= f.submit "I like" %>
 </p>
<% end %>

The update_like method is called in the book.rb model and looks like this:

def update_like(in_book)
    in_book.like_tag = in_book.like_tag + 1;    
end

The update_like methode is called, but the database is not update. I do not grasp what’s going wrong. Any help is much appreciated.

  • 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-16T18:44:18+00:00Added an answer on May 16, 2026 at 6:44 pm

    you don’t know the concept of ruby on rails 😉

    You can’t do it this way, you have to call a controller method to update the database record.

    What you’re looking for is link_to_remote (this will not work with Rails 3!!)

    Have a look at: http://apidock.com/rails/ActionView/Helpers/PrototypeHelper/link_to_remote

    So you create a controller let’s say “CommentsController” and add an action like “like_it”

    Then everything could look like:

    Controller:

    class CommentsController < ApplicationController
    
      def like_it
    
        @book = Book.find(params[:id])
        @book.update_like
    
        render :nothing => true
    
      end
    
    end
    

    Model:

    class Book < ActiveRecord::Base
    
      def update_like
        self.like_tag += 1
        self.save
    
      end
    
    end
    

    In your view:

    link_to_remote "I like it!!", :url => { :controller => 'comments', :action => 'like_it', :id => placeCommentIDHere }, :complete => 'alert('You liked it!!');'
    

    I looked at your profile and saw that you’re from Switzerland too! Maybe you speak German, if you do so you should read this book (it’s free!): http://openbook.galileocomputing.de/ruby_on_rails/

    PS: link_to_remote is no longer supported in Rails 3.0 !!

    Gruess

    Simon 😉

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

Sidebar

Related Questions

No related questions found

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.