Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old November 12th, 2007, 01:45 PM
GlennNZ GlennNZ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 40 GlennNZ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 30 m 58 sec
Reputation Power: 4
How to retrieve an object from form_remote_tag?

If I have a cart object which contains CartItem objects and then use partials to display them, how do I go about getting a copy of a CartItem object to a controller method.

So if a partial displaying a CartItem had this code...
Code:
<% form_remote_tag :url => { :action => :delete_from_cart, :item => cart_item } do %>
  <%= submit_tag "Delete" %>
<% end %>

...then how do I access the CartItem object from the delete_from_cart method.

At the moment I'm just trying to print out the name of the CartItem using something like...
Code:
def delete_from_cart
  print params[:item].name
  #or maybe
  my_item = CartItem.new(params[:item])
  print my_item.name
end


...but neither work so obviously I've completely misinterpreted rails again. I get an error like.
Quote:
NoMethodError (undefined method `name' for "#<CartItem:0x47dd9f4>":String):

Note that I can go <%= cart_item.name %> from the partial and it prints to the browser fine, so there is a name method.

Any help will be great.

Last edited by GlennNZ : November 12th, 2007 at 06:57 PM.

Reply With Quote
  #2  
Old November 13th, 2007, 10:11 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 51 m 47 sec
Reputation Power: 797
Perhaps what you're passing to the partial is not a CartItem object. You could be passing some other object in with the variable name cart_item (Notice the case and the spelling). For instance:
Code:
   product = Product.find(id)
   render :partial => 'partial_template', :locals => { :cart_item => product, :header => 'hello' }

In this case, what is being passed to cart_item is an instance of an object Product, which may actually have a name method. Hence, when your partial does:
Code:
<%= cart_item.name %>

it then works correctly.

One quick way to verify if you're passing a different object to the partial is by doing this:
Code:
<%= cart_item.inspect %>

which should tell you what the object is.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > How to retrieve object from a


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway