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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:28:47+00:00 2026-05-21T11:28:47+00:00

I have a rails app that has some simple functionality, allowing the user to

  • 0

I have a rails app that has some simple functionality, allowing the user to save/unsave posts.

It does this nice and ajaxy, like so:

view:

<p id="save_<%= frugle.id %>">
  <%= link_to "Save", new_saveds_path(current_user.id, :post_id => post.id), :remote => true %>
</p>

controller:

class SavedsController < ApplicationController
  def new
    @follow = Saved.create(:user_id => current_user.id, :post_id => params[:post_id])
    @post = Post.find params[:post_id]
    render :update do |page|
      page.replace_html "save_#{@post.id}", "#{link_to "Unsave", saveds_path(current_user.id, :post_id => @post.id), :method => :delete, :remote => true }"
    end
  end

This works fine and dandy. My question comes in, as sometimes, on the homepage, the user has a whole lot of posts being viewed, and occasionally the same post shows up twice. If the user goes to save this post, the RJS above will just change the first p with that particular id that it comes across then stop. Is there any way to update all the p with that id on a single page?

That makes sense right?

Thanks!

  • 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-21T11:28:48+00:00Added an answer on May 21, 2026 at 11:28 am

    You can’t “update all the ‘p’s with that id”, because by definition only one element on the page has a given id.

    However, if you give all your <p>s a class according to their rails id, you can do what you want.

    Example:

    <p class="object-1234">test</p>
    <p class="object-5678">another test</p>
    <p class="object-1234">test</p>
    

    Now you can do:

    $('.object-1234').hide()
    

    And get the desired effect.

    edit:
    Also, this assumes you’re using jQuery in your AJAX views. I strongly advise you to do so – it’s more useful than the built-in rjs.
    Here’s a screencast about it: http://railscasts.com/episodes/136-jquery

    • 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.