Hi, When I click on "Proceed to Checkout", instead of showing a clean form, it seems as if the form has already been submitted empty and the new page comes up with all the errors -- which I don''t think many customers would appreciate. I am not sure where in the code is the problem. My order.rb class is: --------------------------------- def process result = true # # TODO Charge the customer by calling the payment gateway # TODO email both admin/customer self.status = ''processed'' save! result end protected def set_status self.status = "open" if self.status.blank? end And the cart_controller.rb has: -------------------------------------------- def checkout @page_title = "Checkout" @order = Order.new(params[:order]) @order.customer_ip = request.remote_ip @order.customer_id = @customer.id @order.discount = @customer.discount populate_order if @order.save if @order.process flash[:notice] = ''Your order has been submitted, and will be processed immediately.'' session[:order_id] = @order.id # Empty the cart @cart.cart_items.destroy_all redirect_to :action => ''thank_you'' else flash[:notice] = "Error while placing order. ''#{@order.error_message}''" render :action => ''view_cart'' end else render :action => ''checkout'' end end def thank_you @page_title = ''Thank You!'' end def populate_order for cart_item in @cart.cart_items order_item = OrderItem.new( :product_id => cart_item.product_id, :price => cart_item.price, :amount => cart_item.amount ) @order.order_items << order_item end end Can anyone have a quick look? One more question: I am trying to use select_state plugin in the form. My view has: <label for="order_ship_to_state">State</label> <%= state_options_for_select(selected = nil, country = ''US'') %> But on the page, I only see all the states one after the other instead as a drop down menu. What''s incorrect in this line? Thanks, Elle --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I fixed my state field by using: <%= state_select(object, method) %> But I''m still having troubl with my checkout code. Also If I try and submit the order, nothing happens and I''m back at the same form, showing errors that no information was entered. Would anyone have any ideas what is the problem with my code? TIA, Elle --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I tried to separate my displaying the checkout form and placing the order by spliting the method into: cart_controller.rb: def checkout @page_title = "Checkout" @order = Order.new(params[:order]) @order.customer_ip = request.remote_ip @order.customer_id = @customer.id @order.discount = @customer.discount populate_order end def place_order if @order.save if @order.process flash[:notice] = ''Your order has been submitted, and will be processed immediately.'' session[:order_id] = @order.id # Empty the cart @cart.cart_items.destroy_all redirect_to :action => ''thank_you'' else flash[:notice] = "Error while placing order. ''#{@order.error_message}''" render :action => ''view_cart'' end else render :action => ''checkout'' end end So, now I don''t get any error messages when I click on "Proceed to checkout" but, when I click on "Place Order" I get error messages: NoMethodError in CartController#place_order You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.save app/controllers/cart_controller.rb:99:in `place_order'' Why is that? don''t I have an order object? Elle --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 24 Oct 2007, at 10:55, elle wrote:> > def place_order > if @order.save > if @order.process > flash[:notice] = ''Your order has been submitted, and will be > processed immediately.'' > session[:order_id] = @order.id > # Empty the cart > @cart.cart_items.destroy_all > redirect_to :action => ''thank_you'' > else > flash[:notice] = "Error while placing order. > ''#{@order.error_message}''" > render :action => ''view_cart'' > end > else > render :action => ''checkout'' > end > end > > > > Why is that? don''t I have an order object? >You don''t. Nothing in place_order creates @order Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> You don''t. Nothing in place_order creates @orderI thought of that just after I posted this. So I added @order Order.new, which gave me new errors. So then I thought of something else and it works. So, all the code that was in checkout went into def place_order # original code end and def checkout # only shows the checkout form end So, all is good. Cheers, Elle --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I think you can''t use a variable of one action in another like this Try as session[:order] = @order in def check out and in def place_order if session[:order].save Hope it helps -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---