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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:47:07+00:00 2026-05-15T20:47:07+00:00

I have a shop application and another site thats for a special promotion. I’ve

  • 0

I have a shop application and another site thats for a special promotion. I’ve used Active Resource to import products from the shop in to the promo site and added a shopping cart to add the products. However, to actually order the products I need to send the items to the shop application, creating a new cart there to finish the order.

I’ve made a demo ‘RESTful’ application to practice using xml to send data back and forth, so I’m trying to use the principles of REST for the real app. However, I need to send the products to a non-RESTful controller. Just to give you an idea of the Cart controller in the shop, here are its actions:

def index…
def add…
def checkout…
def update…
def remove…
def empty…
def apply_discount…
def remove_discount…
def apply_credits…
def remove_credits…
def stock_check…

# My action to accept items from carts in other apps
def cart_import…

And in routes.rb, the only route relating to the cart is currently

  map.cart              'cart/:action/:id',       :controller => 'shop/cart'

I’ve inherited the shop application from a previous developer, so I’d probably try to make it more RESTful if I was to make it from scratch.

Anyway, I’m pretty confident that I can get the cart to respond to XML, even without being defined with map.resources. My problem is how to send a hash of the cart items and quantities from the promo app.

To group the cart items and quantities I’ve collected the item’s product id and quantity in to a hash:

<% @items = Hash.new %>
<% @cart.items.collect {|i| @items[i.product_id] = i.quantity} %>

Which when inspected gives the following output:

<%= Rails.logger.info @items.inspect %>
{1144=>2, 1143=>1}

So I figured to send them to the shop I could pass them in a posted link_to:

<%= link_to 'Export Cart', "http://shop.example.com/cart/cart_import", :items => @items, :method => :post %>

That doesn’t seem to do anything, whereas omitting the first field appends the items to the URL in a format that looks sensible, but appears as a relative link on the promo application:

<%= link_to "http://shop.example.com/cart/cart_import", :items => @items, :method => :post %>

http://promo.example.com/cart?items%5B1143%5D=1&items%5B1144%5D=2&method=post

I’m sure the clue is in that the @items object needs to be passed in with the url, but since I can’t use a named route I don’t really know how to get it in there so that it is posted in the correct format.

Thanks for the help,

Gareth

  • 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-15T20:47:08+00:00Added an answer on May 15, 2026 at 8:47 pm

    In the end I made a helper:

    def hash_to_params(items)
      result = ""
       i = 0
       items.each do |item|
         i > 0 ? result += "&" : result += ""
         result += "items[#{item[0]}]=#{item[1]}"
         i += 1
       end
      return result
    end
    

    Then for the link I called the helper:

    <%= link_to "export", "http://shop.example.com/cart/cart_import?#{hash_to_params(@items)}", :method => :post %>
    

    Pretty ugly way of doing it, but I really can’t think of anything better?

    Cheers,

    Gareth

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

Sidebar

Related Questions

I have an application to be used in a shop, where the employee needs
In my application I have a string parameter called shop that is required in
We have a Zend application that has these following modules: Users Shop etc... Front
I have a website where drupal manage the contents, but another application handle the
I am porting an application from foxpro to C#.Net. This is a wine shop
I am creating a stock management application for a jewelry shop. I have completed
I am planning to build a POS Application for my shop. I have enough
In my asp.net application i have url www.site.com/rugby to match it i have regex
I am writing a shop application, and I have a question. As you know
I have a E-Shop Site and I need some customization for my users like

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.