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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:51:51+00:00 2026-05-16T17:51:51+00:00

I have a stripped down shopping cart application, currently with one model cart, the

  • 0

I have a stripped down shopping cart application, currently with one model “cart”, the cart id is stored in a session.

the cart controller has this method so we always have a cart

  def initialize_cart
    if session[:cart_id]
      @cart = Cart.find(session[:cart_id])
    else
      @cart = Cart.create
      session[:cart_id] = @cart.id
    end
  end

my routes file has this one line

  map.resource :cart

my cart/show view looks like this, i have added a form to it so that ultimately i can update the quantity of items, but for now i am just editing the created_at attribute.

<% form_for(@cart) do |f| %>
  <%= f.date_select :created_at %>

  <p>
    <%= f.submit 'Update' %>
  </p>
<% end %>


<%= link_to 'Edit', edit_cart_path(@cart) %> |
<%= link_to 'Back', cart_path %>

and finally, my update action looks like this:

  def update
    #@cart = Cart.find(params[:id])

    respond_to do |format|
      if @cart.update_attributes(params[:cart])
        format.html { redirect_to(cart_path) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @cart.errors, :status => :unprocessable_entity }
      end
    end
  end

when i make a change to “created_at” attribute on the “show” page, the attribute is successfully updated, but when i get redirected, i get a bizare url like this

http://192.168.0.10:3000/cart.%23%3Ccart:0x23d46fc%3E

I have fiddled with the update action, and can get the whole thing to work perfectly by doing this

  # PUT /carts/1
  # PUT /carts/1.xml
  def update
    #@cart = Cart.find(params[:id])

    #respond_to do |format|
      if @cart.update_attributes(params[:cart])
         redirect_to(cart_path) 
        # head :ok 
      #else
        # render :action => "edit" 
        # render :xml => @cart.errors, :status => :unprocessable_entity }
      end
    #end

Its something to do with the respond_to block that is causing it to mess up, i would really appreciate any help i can get with this.

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-16T17:51:51+00:00Added an answer on May 16, 2026 at 5:51 pm

    For singular resource, you don’t need to specify the object in the routes.

    So you should use this:

    <%= link_to 'Edit', edit_cart_path %>
    

    ===== UPDATED =====

    I just found your real problem ^^” (but the original should be true too)

    You used form_for(@cart) do |f|, which produced that ugly path

    Please change to form_for(@cart, :url => cart_path) do |f|

    I don’t know why too, but it should be ok……

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

Sidebar

Related Questions

Currently i have some interfaces (stripped down for here): public interface IJobGroup { string
I have my own stripped down script that currently makes uses of XHR or
I have this kind of HTML structure (stripped down for easy readability): <head> <title>My
Say I have 3 tables in a Tennis Application (stripped down removing irrelevant info):
I have replicated a stripped-down version of my code that has recently been re-written
I have a jQuery function (stripped down just for this example): (function($) { $.fn.Lightbox
I have a simple ANTLR grammar, which I have stripped down to its bare
Given that I have this resultset structure (superfluous fields have been stripped) Id |
I have this horribly stripped delphi code that basically login to server, save cookie
I have existing Linux shared object file (shared library) which has been stripped. I

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.