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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:00:38+00:00 2026-05-11T22:00:38+00:00

I have a virtual shopping cart using sessions (sessions stored in the DB). I

  • 0

I have a virtual shopping cart using sessions (sessions stored in the DB).
I add products to the cart using an AJAX call. This list is also sortable.
The problem I am having is updating the sort position of the products in the cart, given that the shopping cart is virtual. Can anyone help (specifically with the sortable_element :update action). Here is some of the code:

#cart.rb

class Cart
  attr_reader :items   

  def initialize
    @items = []
  end

  def add_product(product
    @items << CartItem.new(product)
  end
end

#cart_item.rb

class CartItem
  attr_reader :product

  def initialize(product)
    @product = product
  end

  def name
    @product.name
  end
end

#cart/index.html.erb

<div id="items">
  <%= render :partial => 'cart', :object => @cart %>
</div>

#cart/_cart.html.erb

<%= render :partial => 'cart_item', :collection => @cart.items %>
<%= sortable_element "items", :url => {:action => :update} %>

#cart/_cart_item.html.erb

<% content_tag_for :li, cart_item do %>
  <p><%= cart_item.name %></p>
<% end %>

#cart_controller.rb

def index
  find_cart
end

def update
  #???? how does I change the sort of @cart?
  render :nothing => true
end

def find_cart
  session[:cart] ||= @cart
end
  • 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-11T22:00:38+00:00Added an answer on May 11, 2026 at 10:00 pm

    look at this solution, I think it will do what you need

    Sort a list of objects by using their attributes in Ruby

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

Sidebar

Related Questions

I have a virtual store and a shopping basket. Also, I have in every
I have this virtual method: const string& my_class::to_string() const { string str(this->name + string(
I have a virtual machine running Windows XP SP3 32-bit. On this machine I
I using XAMPP and I have configure it in order to have virtual hosts
I have a concept of Virtual Mart for my Final year Project. This concept
On my website i'm using virtual host so my users can have virtual domain
I have virtual hosting with SQL Server. I don't have physical access to SQL
If we dont have virtual constructors then why we have virtual destructors? Can constructors
Does anyone know why the STL containers don't have virtual destructors? As far as
I have 2 virtual directory on my IIS (first for server developing and second

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.