|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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:
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. |
|
#2
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > How to retrieve object from a |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|