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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:01:42+00:00 2026-05-13T12:01:42+00:00

I have a very simple cart which displays the item quantity in a text_field,

  • 0

I have a very simple cart which displays the item quantity in a text_field, and the item name. I can fetch the proper data, I can’t pass both of my arguments into my method (inventory ID and quantity). I’m receiving an argument error in my cart_update method of the inventories controller.

add_to_cart.html.erb

<% for item in @cart.items %>
<tr>
<td><% form_for item, :url => {:action => "cart_update", :id => "#{item.getinventoryid}", :quantity => "3"} do |f| %>
  <%= f.text_field :quantity, :size => '3' %>
  <%= f.hidden_field :id, :value => "#{item.getinventoryid}" %>
  <%= f.submit 'cart_update' %>
<% end %></td>
<td><%=h item.title %></li></td>
</tr>
<% end %>

cart_item.rb model

attr_accessor :inventory, :quantity

    def initialize( inventory )
        @inventory = inventory
        @quantity = 1
    end

cart.rb model

attr_accessor :items

def increment_inventory_quantity(inventory, quantity)
   inventory_to_increment = @items.select{|item| item.inventory == inventory}

   # We do this because select will return an array
   unless inventory_to_increment.empty?
      inventory_to_increment = inventory_to_increment.first
   else
      # error handling here
   end

   inventory_to_increment.quantity = quantity
end

inventories_controller.rb

def cart_update
        @inventory = Inventory.find(params[:id])
        @cart = find_cart
        @cart.increment_inventory_quantity(params[:inventory])
    end

The error reads: ArgumentError in InventoriesController#cart_update

inventories_controller.rb:24:in increment_inventory_quantity'
inventories_controller.rb:24:in
cart_update’

With the following Parameters:

{"commit"=>"cart_update",
 "quantity"=>"3",
 "_method"=>"put",
 "authenticity_token"=>"CK6to1uGWPszjz8vfL1Er3DLgi8cIMtLxfFb49a4wCE=",
 "id"=>"5",
 "cart_item"=>{"quantity"=>"11",
 "id"=>"5"}}

I’m really confused because it appears I’m passing the parameters I need. Additionally the url is formatted as: http://localhost:3000/inventories/cart_update/5?quantity=3 which is also what I was expecting to see. What am I doing that is obviously wrong?

Thanks in Advance!

  • 1 1 Answer
  • 3 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-13T12:01:42+00:00Added an answer on May 13, 2026 at 12:01 pm

    Just change line 3 of cart_update, and use this instead:

    if(params[:cart_item] && params[:cart_item][:id])
        @cart.increment_inventory_quantity(params[:cart_item][:id], params[:cart_item][:quantity])
    else
        # Error handling
    end
    

    You can see from your POST data:

    { ... ,
      "cart_item"=>{"quantity"=>"11", "id"=>"5"}
    }
    

    That rails is nesting the cart_item details into its own hash.

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

Sidebar

Related Questions

I have a very simple table called Member , which consists of the following:
I have a very simple highcharts js chart, which has dates on x-axis and
I have written very very simple console application which supports some command line options.
I have very simple query that calls a UDF which splits a field by
I have very simple form, with input like this: <input id=my_id multiple=true type=file name=image_name[]
We have a very simple method that uses findById. public Cart getCart(long cartId) {
I have very simple html and js files - which I've included below. What
I have very simple iPhone app, which uses just UIButtons , UIlabels , UITableView
I have very simple problem that I can't solve. I need to do something
I have a simple shopping cart application that displays the session's shopping cart with

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.