Damon Hill
2005-Aug-11  20:10 UTC
Newbie: Good progress until Shipping; Double Render error
Good day. 
 
I was making great progress with Rails after my initial problem of the
tab until I started implementing the Shipping section.
I added all the functionality, but now when attempting to display the
cart in my application, I am throwing a double render error:
 
Error: ActionController::DoubleRenderError in Store#display_cart
 Render and/or redirect were called multiple times in this action.
Please note that you may only call render OR redirect, and only once per
action. Also note that neither redirect nor render terminate execution
of the action, so if you want to exit an action after redirecting, you
need to do something like "redirect_to(...) and return". Finally, note
that to cause a before filter to halt execution of the rest of the
filter chain, the filter must return false, explicitly, so "render(...)
and return false".
admin_controller.rb with the only difference being the addition of the
ship action at the bottom:
 
 class AdminController < ApplicationController
  def index
    list
    render :action => ''list''
  end
  def list
    @product_pages, @products = paginate :product, :per_page => 10
  end
  def show
    @product = Product.find(params[:id])
  end
  def new
    @product = Product.new
  end
  def create
    @product = Product.new(params[:product])
    if @product.save
      flash[:notice] = ''Product was successfully created.''
      redirect_to :action => ''list''
    else
      render :action => ''new''
    end
  end
  def edit
    @product = Product.find(params[:id])
  end
  def update
    @product = Product.find(params[:id])
    if @product.update_attributes(params[:product])
      flash[:notice] = ''Product was successfully updated.''
      redirect_to :action => ''show'', :id => @product
    else
      render :action => ''edit''
    end
  end
  def destroy
    Product.find(params[:id]).destroy
    redirect_to :action => ''list''
  end
  def ship
        @pending_orders = Order.pending_shipping
  end
end
 
Order.rb with the addition of the pending_shipping action
class Order < ActiveRecord::Base
        has_many :line_items
        validates_presence_of :name, :email, :address, :pay_type
        PAYMENT_TYPES = [
                ["Check", "check"],
                ["Credit Card", "cc"],
                ["Purchase Order", "po"]
        ].freeze  #freeze to make this array constant
        def self.pending_shipping
                find(:all, :conditions => "shipped_at is null")
        end
end
ship.rhtml to display the shipping page of the admin:
h1>Orders To Be Shipped</h1>
<%= form_tag(:action => "ship") %>
<table cellpadding="5" cellspacing="0">
<%= render(:partial => "order_line", :collection =>
@pending_orders) %>
</table>
<br />
<input type="submit" value=" SHIP CHECKED ITEMS " />
<%= end_form_tag %>
<br />
Sorry for all of the code and the apperantly simple problem. 
Thanks in advance for the help.
M Damon Hill
Project Manager
IFWORLD, INC.
www.ifworld.com <http://www.ifworld.com/> 
479.582.5100 (phone)
479.582.5599 (fax)
 
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
Dave Silvester
2005-Aug-11  21:57 UTC
Re: Newbie: Good progress until Shipping; Double Render error
Damon Hill wrote:> I added all the functionality, but now when attempting to display the > cart in my application, I am throwing a double render error:Hi Damon, I''m still very new to all this myself, although thanks to throwing myself in at the deep end, I''m starting to get used to figuring out the errors... today has been a much better day than yesterday was! Anyway, I''m not sure you''ve included the relevant bit of code that''s throwing up the error (Store#display_cart), so I don''t think we can fix it from the code you posted. However, have you read the following: http://jamis.jamisbuck.org/articles/2005/07/08/rails-tip-of-the-day That might help you? ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
M Damon Hill
2005-Aug-12  13:14 UTC
RE: Newbie: Good progress until Shipping; Double Render error
David---
Thank you for the website. I remember reading over that a few weeks ago, but
had obviously forgotten about it :)
That cleared up the double render error for sure.
The only small issue that I have now is when I click to display my cart, it
shows the cart contents listed correctly, however, the surrounding styles of
the overall site are completely missing. My page looks like the following:
 
    * Continue Shopping
Qty 	Description 	Price
Each 	Total
1 	iPod 20 GB 	299.0 	299.0
1 	XBox 	195.0 	195.0
Total: 	$494.00
It doesn''t have any of the styles as it should as showed on page 114 of
the
Agile book.
Thoughts? 
Files you might need to see?
Thanks again for the help everyone.
~d
However, have you read the following:
http://jamis.jamisbuck.org/articles/2005/07/08/rails-tip-of-the-day
That might help you?
~Dave
Justin Forder
2005-Aug-13  10:59 UTC
Re: Newbie: Good progress until Shipping; Double Render error
M Damon Hill wrote:> The only small issue that I have now is when I click to display my cart, it > shows the cart contents listed correctly, however, the surrounding styles of > the overall site are completely missing. My page looks like the following: > > > > * Continue Shopping > > Qty Description Price > Each Total > 1 iPod 20 GB 299.0 299.0 > 1 XBox 195.0 195.0 > Total: $494.00 > > It doesn''t have any of the styles as it should as showed on page 114 of the > Agile book. > Thoughts? > Files you might need to see?There is a step in the tutorial when the Cart display is made reusable as a component. A little logic is added to decide whether or not it is being used as a component in the checkout page, or is being used as a complete page. In the former case, the layout is suppressed. It looks as if you have an error in this area (the display_cart code at the top of page 107). Just guessing, but did you mistype == as = in the test? def display_cart @cart = find_cart @items = @cart.items if @items.empty? redirect_to_index("Your cart is currently empty") end if params[:context] == :checkout render(:layout => false) end end regards Justin
M Damon Hill
2005-Aug-13  13:53 UTC
RE: Newbie: Good progress until Shipping; Double Render error
Andrew-- Thanks for the suggestion. That was EXACTLY the problem. This list is great and you guys provide a wealth of insight into this new framework. I appreciate all of the time and effort you put into your responses. Hopefully one day soon I will be able to contribute to the list. Thanks again, ~damon -----Original Message----- From: Andrew Otwell [mailto:andrew-uQjPo4GTFqgS+FvcfC7Uqw@public.gmane.org] Sent: Friday, August 12, 2005 1:14 PM To: damon-PtLKVMudsehBDgjK7y7TUQ@public.gmane.org Subject: RE: [Rails] Newbie: Good progress until Shipping; Double Render error> The only small issue that I have now is when I click to display my > cart, it shows the cart contents listed correctly, however, the > surrounding styles of the overall site are completely missing.You mean the content of the layout isn''t there? No left-nav or visual styling? display_cart is used as a component, and uses render(:layout => false) to specifically *not* show those styles when it''s used as part of the checkout page. You''re seeing display_cart on its own. Since no layout is being applied, probably your display_cart action is incorrect. Check that display_cart is: def display_cart @cart = find_cart @items = @cart.items if @items.empty? redirect_to_index("Your cart is currently empty") end if params[:context] == :checkout render(:layout => false) end end Here''s my guess: you typed that last condition with only one "=", which would make that condition *always* evaluate as true, and therefore use no layout in all situations. Andrew