Forum: Ruby on Rails Can't get data from products into @order

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
charlie bowman (Guest)
on 2005-12-23 20:27
I went throught the "agile web developemnt with rails" and Now I'm
trying to 'enhance' the code with some extra options.  When I go to
admin/shipping I want to include some data from the products table in
with the order info listed.  I can't seem to get this to work.  in my
partial form I'm trying to add this:

<td class="olnamebox">
  <%= order_line.image_url %>
</td>

I'm recieving this error
undefined method `image_url' for #<Order:0xb77ee194>

I call the partial with:
<table cellpadding="5" cellspacing="0">
<%= render(:partial => "order_line", :collection => @pending_orders) %>
</table>

Here is how I get @pending_orders
@pending_orders = Order.pending_shipping

and finally my order class
class Order < ActiveRecord::Base

  has_many :line_items

  # function to retrieve all orders that haven't been marked as shipped
yet.
  # this allows us to see what orders have been made
  def self.pending_shipping
    find(:all, :conditions => "shipped_at is null")
  end

end

What do I need to do to get some product data into my shipping view?
Gerard (Guest)
on 2005-12-23 22:21
(Received via mailing list)
Charlie,

Could be that image_url is not known in the model for order_line. I
think it
should be something like "order_line.image_url = product.image_url"

Something similar is done in the books example webshop in
models/line_item.rb
with: "item.unit_price = product.price"

Hope it helps.

Gerard.


On Friday 23 December 2005 19:27, charlie bowman tried to type something
like:
> I'm recieving this error
> and finally my order class
>
> end
>
> What do I need to do to get some product data into my shipping view?

--
"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
~
:wq!
charlie bowman (Guest)
on 2005-12-23 23:00
order_line isn't acutally a model. It is the name of the partial form.
it holds the value @pending_orders.  I need to get data from the product
table into @pending_orders.

Gerard wrote:
> Charlie,
>
> Could be that image_url is not known in the model for order_line. I
> think it
> should be something like "order_line.image_url = product.image_url"
>
> Something similar is done in the books example webshop in
> models/line_item.rb
> with: "item.unit_price = product.price"
>
> Hope it helps.
>
> Gerard.
>
Charlie B. (Guest)
on 2005-12-23 23:01
(Received via mailing list)
order_line isn't actually a model.  it is the name of
the partial form.  Within that form order_line holds
the value of @pending_orders.  I need product info in
pending orders.

--- Gerard <removed_email_address@domain.invalid> wrote:

>
> options.  When I go to
> > I'm recieving this error
> > @pending_orders = Order.pending_shipping
> made
> --
>
__________________________________
Yahoo! for Good - Make a difference this year.
http://brand.yahoo.com/cybergivingweek2005/
Gerard (Guest)
on 2005-12-23 23:58
(Received via mailing list)
Charlie,

Mind you I'm a newbie so this discussion might end up beyond the scope
of my
knowledge. Nevertheless, digging back in the book, the data needs to be
available in the controller (getting it from the model) when you want to
display it in the view. Product info is available (in the admin
controller)
when generating the "orders pending" list. Have you simply tried
"product.image_url".

Regards,

Gerard.


On Friday 23 December 2005 22:00, charlie bowman tried to type something
like:
> >
> > Something similar is done in the books example webshop in
> > models/line_item.rb
> > with: "item.unit_price = product.price"
> >
> > Hope it helps.
> >
> > Gerard.

--
"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
~
:wq!
Gerard (Guest)
on 2005-12-24 00:16
(Received via mailing list)
Charlie,

When adding a line to "views/admin/_order_line.rhtml"
(The one with <<< behind it)

  <td class="olitembox">
    <% order_line.line_items.each do |li| %>
      <div class="olitem">
        <span class="olitemqty"><%=  li.quantity %></span>
        <span class="olitemtitle"><%= li.product.title %></span>
        <span class="olitemtitle"><%= li.product.image_url %></span>
<<<<
      </div>
    <% end %>
  </td>

It shows /images/picture.jpg in the html output. So when encapsulated in
an
<img> tag you should see a picture.

Is that's what your looking for?

Regards,

Gerard.


On Friday 23 December 2005 22:00, charlie bowman tried to type something
like:
> >
> > Something similar is done in the books example webshop in
> > models/line_item.rb
> > with: "item.unit_price = product.price"
> >
> > Hope it helps.
> >
> > Gerard.

--
"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
~
:wq!
This topic is locked and can not be replied to.