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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:15:50+00:00 2026-06-15T07:15:50+00:00

I recently started with Rails 3.2 and am stuck while trying to implement some

  • 0

I recently started with Rails 3.2 and am stuck while trying to implement some ajax functionality in my app. I followed this railscast completely (http://railscasts.com/episodes/240-search-sort-paginate-with-ajax). Beyond this I want to implement a shortlist button for each product which lets user shortlist products and store them in the session. I also want a small list of shortlisted products to show up on the same page, which needs to be ajax updated.

I am wondering what is the best way to do that. I currently implemented the link_to buttons with remote tag and a helper function to change the link to shortlist/unshortlist. I also, used a conditional div to show the shortlist based on the length of shortlist. However, the issue is that whenever I shortlist, the order of the products table is also reset.

Here are snippets of my code :-

Application_helper.rb

def shortlist_unshortlist_link(product_id )
  if (user_session.already_shortlisted? product_id )
    link_to 'Unshortlist', { action: 'unshortlist', id: product_id  }, remote => 'true'
  else
    link_to 'Shortlist', { action: 'shortlist', id: product_id  }, remote => 'true'
  end
end


def shortlist_div
  shortlist=user_session.shortlist
   if (user_session.shortlist.length > 0)
     render :partial => 'pages/shortlist_fields'
   end
end

products/index.html.erb

<div id="product">
 <% @products.each do |product| %>
<tr>....
<td><%= shortlist_unshortlist_link(product.id.to_s) %></td>
</table>
</div>
<div class="shortlist"><%= shortlist_div() %> </div>

products_controller.rb

def shortlist
 user_session.add_to_shortlist(params[:id])
 redirect_to products_path
end

def unshortlist
 user_session.remove_from_shortlist(params[:id])
 redirect_to products_path
end

I think, the issue is because of redirect_to, but I am not getting how to avoid this without hurting the functionality. Am I on a totally wrong path here. Is this a good way to implement this. Any suggestions.

thanks,
Amit

  • 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-15T07:15:52+00:00Added an answer on June 15, 2026 at 7:15 am

    you should use in shortlist method,

    respond_to do |format|
      format.html {redirect_to products_path }#shortlist.html.erb
      format.js #shortlist.js.erb
     end
    

    and write your java script to #shortlist.js.erb file.

    Do the same with unshortlist.

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

Sidebar

Related Questions

I've recently started trying to build a file uploader on Rails. I did some
I've got some experience using haml (+sass) on rails projects. I recently started using
I've recently started doing some ruby on rails development on Windows 7 and have
I recently started seeing this error message when trying to run any Cucumber tests.
I've recently started reading up on Rails and while getting my development environment ready
I've started learning Rails recently and have completed the sample app at http://ruby.railstutorial.org .
I recently started working with rails 3. I'm trying to add a multi-modal form
I'm coming from C#, and recently I started to write some Ruby on Rails
I just recently started this ruby on rails tutorial to kick off my new
Recently I have started learning rails and was a little surprised that the default

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.