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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:51:46+00:00 2026-06-08T04:51:46+00:00

I have a list of images each with a ‘Like’ button. When the ‘Like’

  • 0

I have a list of images each with a ‘Like’ button. When the ‘Like’ button is clicked, an AJAX request (containing the item_id and user_id) will be sent to the serverside to record the Like (by adding a new row in the table likes with values for item_id and user_id).

The model Photo is used for the images displayed on the page. If I understand correctly, this.model.save() is used if I want to update/add a new Photo, so it is not suitable for recording ‘Likes’. Therefore, I have to use something like $.get() or $.post(). Is this the conventional way?

Or do I create a new model called Like as shown below, which seems to make it messier to have a View and template just for a Like button.

Like = Backbone.Model.extend({
    url: 'likes'
});

LikeView = Backbone.View.extend({

    template: _.template( $('#tpl-like').html() ),

    events: {
        'click .btn_like': 'like'
    },

    like: function() {
        this.model.save({
            user_id: 1234,
            post_id: 10000
        })
    }
});
  • 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-06-08T04:51:47+00:00Added an answer on June 8, 2026 at 4:51 am

    In similar cases to this I’ve used the $.get method rather than create a new model, obviously this will depend on your application, but here are my reasons.

    This case appears to have the following characteristics:

    1. Like is a relationship between a person and a photo,
    2. you seem to have a server side resource that accepts the photo and user ids to create this relationship already,
    3. you probably have no other information attached to that relationship, and
    4. you probably don’t have significant view logic to go with the like itself

    This is better handled by adding another attribute to your Photo object, that contains the number of likes. Then use $.get to create the like, and a 200 response will simply update the photo object to up it’s count (and hence the view). Then the server side just needs to include the like count as part of it when it returns.

    I’m assuming here that once a like is made you won’t be updating it. If you do need to update or delete it, I might still keep using the $.get. You can add a likes array to your photo object where each element is the id of the like resource. The view will display the length of the array as the count, and if you need to delete the like, you have access to the id and you can use $.post. Just make sure you don’t use .push to add values to your array since that’ll bypass backbone’s set method and you won’t get your event callbacks. You need to clone the array, then push, and then set it when you make changes.

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

Sidebar

Related Questions

I have a list of images and a delete button attached with each image.
I have a list containing four images. Each image should only have one active
I have a list of images in a table like so: <div id=scroll-uploader-photos> <table>
I have a list of images that float alongside each other and some links
i have a list of images which i am getting through ajax and then
I have a list of small images while clicking on each of them they
I have a list of items & they are holding images, each image is
i have image collection @images = Image.find(:all) and displaying it like this <%@images.each do|image|%>
I have a list of images, which I'd like to stack, one on top
I have list items with empty checkbox images to the left of each item.

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.