I actually have 2 questions: 1. Right now when a customer logs in, he gets redirected to the 1st page in the catalog, and the cart session is stored in the database. How can I redirect the customer to his last visited page at login? 2. When the same customer checks out, he needs to fill out his address. There is a model for customers, which the administrator controls. The administrator can enter the customer''s email, address, phone and so on. How can I make that the details that are on file, get remembered and automatically filled out in the checkout form (so the customer does not have to enter them again and again)? The models are: cart - controls checkout order customer ... Relationships in the Cart class are: has_many :cart_items has_many :products, :through => :cart_items belongs_to :customer An example from my checkout form: <p><label for="order_email">Email</label></p> <p><%= text_field :order, :email %></p> Any help will be much appreciated. 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 -~----------~----~----~----~------~----~------~--~---
On Dec 27, 2007 10:35 PM, elle <waznelle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I actually have 2 questions: > 1. Right now when a customer logs in, he gets redirected to the 1st > page in the catalog, and the cart session is stored in the database. > How can I redirect the customer to his last visited page at login?You have to store it somewhere, in the database or in a cookie perhaps?> 2. When the same customer checks out, he needs to fill out his > address. There is a model for customers, which the administrator > controls. The administrator can enter the customer''s email, address, > phone and so on. > How can I make that the details that are on file, get remembered and > automatically filled out in the checkout form (so the customer does > not have to enter them again and again)? > > The models are: > cart - controls checkout > order > customer > ... > > Relationships in the Cart class are: > has_many :cart_items > has_many :products, :through => :cart_items > belongs_to :customer > > An example from my checkout form: > <p><label for="order_email">Email</label></p> > <p><%= text_field :order, :email %></p>Are you actually storing an email address with every order? Seems like you''d just want to store the user''s id of who placed the order. Then you can get the email from that user record. -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
> Are you actually storing an email address with every order? Seems > like you''d just want to store the user''s id of who placed the order. > Then you can get the email from that user record.Yes, I do. And shipping address and... Could I use something like that: <p><label for="order_email">Email</label></p> <p><%= text_field_tag "email", "#{customer.email}" %></p> instead of: <p><label for="order_email">Email</label></p> <p><%= text_field :order, :email %></p> Would Rails know to find that info? and would it still know where that info should be stored? 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 -~----------~----~----~----~------~----~------~--~---
Actually this gave me an error, but when changing it to: <%= text_field_tag "email", @cart.customer.email %> it worked. Still one last question: will rails know that I want to save that email address in the orders table? And also, trying to checkout, I now get an error: There were problems with the following fields: Email is invalid ... but the email is valid. What is the problem then? Elle On Jan 8, 4:33 pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Are you actually storing an email address with every order? Seems > > like you''d just want to store the user''s id of who placed the order. > > Then you can get the email from that user record. > > Yes, I do. And shipping address and... > Could I use something like that: > <p><label for="order_email">Email</label></p> > <p><%= text_field_tag "email", "#{customer.email}" %></p> > > instead of: > <p><label for="order_email">Email</label></p> > <p><%= text_field :order, :email %></p> > > Would Rails know to find that info? and would it still know where that > info should be stored? > > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You''re using a text_field_tag, try specifying <%= text_field "order", "email", @cart.customer.email %> instead. On Jan 8, 2008 4:14 PM, elle <waznelle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Actually this gave me an error, but when changing it to: > <%= text_field_tag "email", @cart.customer.email %> > it worked. > Still one last question: will rails know that I want to save that > email address in the orders table? > And also, trying to checkout, I now get an error: > > There were problems with the following fields: > Email is invalid > > ... but the email is valid. > What is the problem then? > > Elle > > > > > > On Jan 8, 4:33pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Are you actually storing an email address with every order? Seems > > > like you''d just want to store the user''s id of who placed the order. > > > Then you can get the email from that user record. > > > > Yes, I do. And shipping address and... > > Could I use something like that: > > <p><label for="order_email">Email</label></p> > > <p><%= text_field_tag "email", "#{customer.email}" %></p> > > > > instead of: > > <p><label for="order_email">Email</label></p> > > <p><%= text_field :order, :email %></p> > > > > Would Rails know to find that info? and would it still know where that > > info should be stored? > > > > Elle > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This gets an error: TypeError in Cart#checkout Showing app/views/cart/checkout.rhtml where line #17 raised: can''t convert Symbol into String 17: <p><%= text_field "order", "email", @cart.customer.email %></ p> Elle On Jan 8, 4:46 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You''re using a text_field_tag, try specifying <%= text_field "order", > "email", @cart.customer.email %> instead. > > On Jan 8, 2008 4:14 PM, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Actually this gave me an error, but when changing it to: > > <%= text_field_tag "email", @cart.customer.email %> > > it worked. > > Still one last question: will rails know that I want to save that > > email address in the orders table? > > And also, trying to checkout, I now get an error: > > > There were problems with the following fields: > > Email is invalid > > > ... but the email is valid. > > What is the problem then? > > > Elle > > > On Jan 8, 4:33pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Are you actually storing an email address with every order? Seems > > > > like you''d just want to store the user''s id of who placed the order. > > > > Then you can get the email from that user record. > > > > Yes, I do. And shipping address and... > > > Could I use something like that: > > > <p><label for="order_email">Email</label></p> > > > <p><%= text_field_tag "email", "#{customer.email}" %></p> > > > > instead of: > > > <p><label for="order_email">Email</label></p> > > > <p><%= text_field :order, :email %></p> > > > > Would Rails know to find that info? and would it still know where that > > > info should be stored? > > > > Elle > > -- > Ryan Bigghttp://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If I use this version: <%= text_field_tag "email", @cart.customer.email %> The email gets displayed and when I use debug to check type, the type of @cart.customer.email is String. But then I get an error that the email address is invalid, even though it is. If I use: <%= text_field "order", "email", @cart.customer.email %> I get: TypeError in Cart#checkout Showing app/views/cart/checkout.rhtml where line #17 raised: can''t convert Symbol into String Would anyone have a solution? or know what the problem is? Thanks, Elle On Jan 8, 4:59 pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This gets an error: > > TypeError in Cart#checkout > Showing app/views/cart/checkout.rhtml where line #17 raised: > can''t convert Symbol into String > > 17: <p><%= text_field "order", "email", @cart.customer.email %></ > p> > > Elle > > On Jan 8, 4:46 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > You''re using a text_field_tag, try specifying <%= text_field "order", > > "email", @cart.customer.email %> instead. > > > On Jan 8, 2008 4:14 PM, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Actually this gave me an error, but when changing it to: > > > <%= text_field_tag "email", @cart.customer.email %> > > > it worked. > > > Still one last question: will rails know that I want to save that > > > email address in the orders table? > > > And also, trying to checkout, I now get an error: > > > > There were problems with the following fields: > > > Email is invalid > > > > ... but the email is valid. > > > What is the problem then? > > > > Elle > > > > On Jan 8, 4:33pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Are you actually storing an email address with every order? Seems > > > > > like you''d just want to store the user''s id of who placed the order. > > > > > Then you can get the email from that user record. > > > > > Yes, I do. And shipping address and... > > > > Could I use something like that: > > > > <p><label for="order_email">Email</label></p> > > > > <p><%= text_field_tag "email", "#{customer.email}" %></p> > > > > > instead of: > > > > <p><label for="order_email">Email</label></p> > > > > <p><%= text_field :order, :email %></p> > > > > > Would Rails know to find that info? and would it still know where that > > > > info should be stored? > > > > > Elle > > > -- > > Ryan Bigghttp://www.frozenplague.net > > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Is there an @order instance variable defined? What is the backtrace on that error? On Jan 9, 2008 8:51 AM, elle <waznelle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > If I use this version: > <%= text_field_tag "email", @cart.customer.email %> > The email gets displayed and when I use debug to check type, the type > of @cart.customer.email is String. > But then I get an error that the email address is invalid, even though > it is. > > If I use: > <%= text_field "order", "email", @cart.customer.email %> > I get: > TypeError in Cart#checkout > Showing app/views/cart/checkout.rhtml where line #17 raised: > can''t convert Symbol into String > > Would anyone have a solution? or know what the problem is? > > Thanks, > Elle > > > On Jan 8, 4:59pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > This gets an error: > > > > TypeError in Cart#checkout > > Showing app/views/cart/checkout.rhtml where line #17 raised: > > can''t convert Symbol into String > > > > 17: <p><%= text_field "order", "email", @cart.customer.email %></ > > p> > > > > Elle > > > > On Jan 8, 4:46pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > You''re using a text_field_tag, try specifying <%= text_field "order", > > > "email", @cart.customer.email %> instead. > > > > > On Jan 8, 2008 4:14 PM, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Actually this gave me an error, but when changing it to: > > > > <%= text_field_tag "email", @cart.customer.email %> > > > > it worked. > > > > Still one last question: will rails know that I want to save that > > > > email address in the orders table? > > > > And also, trying to checkout, I now get an error: > > > > > > There were problems with the following fields: > > > > Email is invalid > > > > > > ... but the email is valid. > > > > What is the problem then? > > > > > > Elle > > > > > > On Jan 8, 4:33pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Are you actually storing an email address with every order? > Seems > > > > > > like you''d just want to store the user''s id of who placed the > order. > > > > > > Then you can get the email from that user record. > > > > > > > Yes, I do. And shipping address and... > > > > > Could I use something like that: > > > > > <p><label for="order_email">Email</label></p> > > > > > <p><%= text_field_tag "email", "#{customer.email}" %></p> > > > > > > > instead of: > > > > > <p><label for="order_email">Email</label></p> > > > > > <p><%= text_field :order, :email %></p> > > > > > > > Would Rails know to find that info? and would it still know where > that > > > > > info should be stored? > > > > > > > Elle > > > > > -- > > > Ryan Bigghttp://www.frozenplague.net > > > Feel free to add me to MSN and/or GTalk as this email. > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
No @order instance. The order is created and populated once the user clicks "process". Application trace is: #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/ form_helper.rb:162:in `delete'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/ form_helper.rb:162:in `text_field'' #{RAILS_ROOT}/app/views/cart/checkout.rhtml:18:in `_run_rhtml_47app47views47cart47checkout46rhtml'' Is this any help? Elle On Jan 9, 9:48 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is there an @order instance variable defined? > > What is the backtrace on that error? > > On Jan 9, 2008 8:51 AM, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > If I use this version: > > <%= text_field_tag "email", @cart.customer.email %> > > The email gets displayed and when I use debug to check type, the type > > of @cart.customer.email is String. > > But then I get an error that the email address is invalid, even though > > it is. > > > If I use: > > <%= text_field "order", "email", @cart.customer.email %> > > I get: > > TypeError in Cart#checkout > > Showing app/views/cart/checkout.rhtml where line #17 raised: > > can''t convert Symbol into String > > > Would anyone have a solution? or know what the problem is? > > > Thanks, > > Elle > > > On Jan 8, 4:59pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > This gets an error: > > > > TypeError in Cart#checkout > > > Showing app/views/cart/checkout.rhtml where line #17 raised: > > > can''t convert Symbol into String > > > > 17: <p><%= text_field "order", "email", @cart.customer.email %></ > > > p> > > > > Elle > > > > On Jan 8, 4:46pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > You''re using a text_field_tag, try specifying <%= text_field "order", > > > > "email", @cart.customer.email %> instead. > > > > > On Jan 8, 2008 4:14 PM, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Actually this gave me an error, but when changing it to: > > > > > <%= text_field_tag "email", @cart.customer.email %> > > > > > it worked. > > > > > Still one last question: will rails know that I want to save that > > > > > email address in the orders table? > > > > > And also, trying to checkout, I now get an error: > > > > > > There were problems with the following fields: > > > > > Email is invalid > > > > > > ... but the email is valid. > > > > > What is the problem then? > > > > > > Elle > > > > > > On Jan 8, 4:33pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Are you actually storing an email address with every order? > > Seems > > > > > > > like you''d just want to store the user''s id of who placed the > > order. > > > > > > > Then you can get the email from that user record. > > > > > > > Yes, I do. And shipping address and... > > > > > > Could I use something like that: > > > > > > <p><label for="order_email">Email</label></p> > > > > > > <p><%= text_field_tag "email", "#{customer.email}" %></p> > > > > > > > instead of: > > > > > > <p><label for="order_email">Email</label></p> > > > > > > <p><%= text_field :order, :email %></p> > > > > > > > Would Rails know to find that info? and would it still know where > > that > > > > > > info should be stored? > > > > > > > Elle > > > > > -- > > > > Ryan Bigghttp://www.frozenplague.net > > > > Feel free to add me to MSN and/or GTalk as this email. > > -- > Ryan Bigghttp://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Indeed it is, define @order = Order.new in the controller and it might get rid of your problem. What it''s trying to do is to find an order instance variable with an email method on it, but maybe because you don''t have it defined it''s throwing that error. On Jan 9, 2008 11:22 AM, elle <waznelle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > No @order instance. The order is created and populated once the user > clicks "process". > > Application trace is: > #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/ > form_helper.rb:162:in `delete'' > #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/ > form_helper.rb:162:in `text_field'' > #{RAILS_ROOT}/app/views/cart/checkout.rhtml:18:in > `_run_rhtml_47app47views47cart47checkout46rhtml'' > > Is this any help? > Elle > > On Jan 9, 9:48am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Is there an @order instance variable defined? > > > > What is the backtrace on that error? > > > > On Jan 9, 2008 8:51 AM, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > If I use this version: > > > <%= text_field_tag "email", @cart.customer.email %> > > > The email gets displayed and when I use debug to check type, the type > > > of @cart.customer.email is String. > > > But then I get an error that the email address is invalid, even though > > > it is. > > > > > If I use: > > > <%= text_field "order", "email", @cart.customer.email %> > > > I get: > > > TypeError in Cart#checkout > > > Showing app/views/cart/checkout.rhtml where line #17 raised: > > > can''t convert Symbol into String > > > > > Would anyone have a solution? or know what the problem is? > > > > > Thanks, > > > Elle > > > > > On Jan 8, 4:59pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > This gets an error: > > > > > > TypeError in Cart#checkout > > > > Showing app/views/cart/checkout.rhtml where line #17 raised: > > > > can''t convert Symbol into String > > > > > > 17: <p><%= text_field "order", "email", @cart.customer.email %></ > > > > p> > > > > > > Elle > > > > > > On Jan 8, 4:46pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > You''re using a text_field_tag, try specifying <%= text_field > "order", > > > > > "email", @cart.customer.email %> instead. > > > > > > > On Jan 8, 2008 4:14 PM, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > Actually this gave me an error, but when changing it to: > > > > > > <%= text_field_tag "email", @cart.customer.email %> > > > > > > it worked. > > > > > > Still one last question: will rails know that I want to save > that > > > > > > email address in the orders table? > > > > > > And also, trying to checkout, I now get an error: > > > > > > > > There were problems with the following fields: > > > > > > Email is invalid > > > > > > > > ... but the email is valid. > > > > > > What is the problem then? > > > > > > > > Elle > > > > > > > > On Jan 8, 4:33pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > Are you actually storing an email address with every order? > > > Seems > > > > > > > > like you''d just want to store the user''s id of who placed > the > > > order. > > > > > > > > Then you can get the email from that user record. > > > > > > > > > Yes, I do. And shipping address and... > > > > > > > Could I use something like that: > > > > > > > <p><label for="order_email">Email</label></p> > > > > > > > <p><%= text_field_tag "email", "#{customer.email}" %></p> > > > > > > > > > instead of: > > > > > > > <p><label for="order_email">Email</label></p> > > > > > > > <p><%= text_field :order, :email %></p> > > > > > > > > > Would Rails know to find that info? and would it still know > where > > > that > > > > > > > info should be stored? > > > > > > > > > Elle > > > > > > > -- > > > > > Ryan Bigghttp://www.frozenplague.net > > > > > Feel free to add me to MSN and/or GTalk as this email. > > > > -- > > Ryan Bigghttp://www.frozenplague.net > > Feel free to add me to MSN and/or GTalk as this email. > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This is my cart_controller#place_order: def place_order @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 Should I define it in another place? Elle On Jan 9, 11:54 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Indeed it is, define @order = Order.new in the controller and it might get > rid of your problem. What it''s trying to do is to find an order instance > variable with an email method on it, but maybe because you don''t have it > defined it''s throwing that error. > > On Jan 9, 2008 11:22 AM, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > No @order instance. The order is created and populated once the user > > clicks "process". > > > Application trace is: > > #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/ > > form_helper.rb:162:in `delete'' > > #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/ > > form_helper.rb:162:in `text_field'' > > #{RAILS_ROOT}/app/views/cart/checkout.rhtml:18:in > > `_run_rhtml_47app47views47cart47checkout46rhtml'' > > > Is this any help? > > Elle > > > On Jan 9, 9:48am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Is there an @order instance variable defined? > > > > What is the backtrace on that error? > > > > On Jan 9, 2008 8:51 AM, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > If I use this version: > > > > <%= text_field_tag "email", @cart.customer.email %> > > > > The email gets displayed and when I use debug to check type, the type > > > > of @cart.customer.email is String. > > > > But then I get an error that the email address is invalid, even though > > > > it is. > > > > > If I use: > > > > <%= text_field "order", "email", @cart.customer.email %> > > > > I get: > > > > TypeError in Cart#checkout > > > > Showing app/views/cart/checkout.rhtml where line #17 raised: > > > > can''t convert Symbol into String > > > > > Would anyone have a solution? or know what the problem is? > > > > > Thanks, > > > > Elle > > > > > On Jan 8, 4:59pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > This gets an error: > > > > > > TypeError in Cart#checkout > > > > > Showing app/views/cart/checkout.rhtml where line #17 raised: > > > > > can''t convert Symbol into String > > > > > > 17: <p><%= text_field "order", "email", @cart.customer.email %></ > > > > > p> > > > > > > Elle > > > > > > On Jan 8, 4:46pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > You''re using a text_field_tag, try specifying <%= text_field > > "order", > > > > > > "email", @cart.customer.email %> instead. > > > > > > > On Jan 8, 2008 4:14 PM, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > Actually this gave me an error, but when changing it to: > > > > > > > <%= text_field_tag "email", @cart.customer.email %> > > > > > > > it worked. > > > > > > > Still one last question: will rails know that I want to save > > that > > > > > > > email address in the orders table? > > > > > > > And also, trying to checkout, I now get an error: > > > > > > > > There were problems with the following fields: > > > > > > > Email is invalid > > > > > > > > ... but the email is valid. > > > > > > > What is the problem then? > > > > > > > > Elle > > > > > > > > On Jan 8, 4:33pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Are you actually storing an email address with every order? > > > > Seems > > > > > > > > > like you''d just want to store the user''s id of who placed > > the > > > > order. > > > > > > > > > Then you can get the email from that user record. > > > > > > > > > Yes, I do. And shipping address and... > > > > > > > > Could I use something like that: > > > > > > > > <p><label for="order_email">Email</label></p> > > > > > > > > <p><%= text_field_tag "email", "#{customer.email}" %></p> > > > > > > > > > instead of: > > > > > > > > <p><label for="order_email">Email</label></p> > > > > > > > > <p><%= text_field :order, :email %></p> > > > > > > > > > Would Rails know to find that info? and would it still know > > where > > > > that > > > > > > > > info should be stored? > > > > > > > > > Elle > > > > > > > -- > > > > > > Ryan Bigghttp://www.frozenplague.net > > > > > > Feel free to add me to MSN and/or GTalk as this email. > > > > -- > > > Ryan Bigghttp://www.frozenplague.net > > > Feel free to add me to MSN and/or GTalk as this email. > > -- > Ryan Bigghttp://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bah! I''m stupid. You should be specifying <%= text_field "order", "email", :value => @ cart.customer.email %> instead of: <%= text_field "order", "email", @cart.customer.email %> Be back later, banging my head against the desk. -- Ryan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Between the two of us, I would be the stupid one, not you :) And I learn something new every day. So, I can use :value to specify what shows in the field. But I now have a new question: I have all the states in an array and I use an iterator to print out all the states. Now, I want the customer''s state to be pre-selected, so, my logic says to use something like that: states.each do | state | %> <option value="<%= state %>" <%= if state == @cart.customer.ship_to_state then puts ''selected="selected"'' end %> ><%= state %></option> <% end %> ...but this doesn''t work. It just prints the normal list of states, with none selected. What should I change? Elle On Jan 9, 12:08 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Bah! I''m stupid. > > You should be specifying <%= text_field "order", "email", :value => @ > cart.customer.email %> instead of: > > <%= text_field "order", "email", @cart.customer.email %> > > Be back later, banging my head against the desk. > > -- > Ryan--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Why wouldn''t you do something along the lines of: # your_controller.rb @some_states_and_provinces = [''alabama'', ''arkansas'', ''canberra'', ''new south wales''].map{|s| [s,s]} @selection = ''canberra'' # your_view.rhtml <%= select(''order'', ''state'', @some_states_and_provinces, :first, :first, @selection) %> I don''t know what your fields are, but chances are there''s a Rails helper to take care of your problem. On Jan 10, 2008, at 8:08 PM, elle wrote:> > Between the two of us, I would be the stupid one, not you :) > And I learn something new every day. > So, I can use :value to specify what shows in the field. > > But I now have a new question: I have all the states in an array and I > use an iterator to print out all the states. > Now, I want the customer''s state to be pre-selected, so, my logic says > to use something like that: > states.each do | state | %> > <option value="<%= state %>" > <%= if state == @cart.customer.ship_to_state then puts > ''selected="selected"'' end %> ><%= state %></option> > <% end %> > ...but this doesn''t work. It just prints the normal list of states, > with none selected. > What should I change? > > Elle > > > On Jan 9, 12:08 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Bah! I''m stupid. >> >> You should be specifying <%= text_field "order", "email", :value => @ >> cart.customer.email %> instead of: >> >> <%= text_field "order", "email", @cart.customer.email %> >> >> Be back later, banging my head against the desk. >> >> -- >> Ryan > >--~--~---------~--~----~------------~-------~--~----~ 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 11 Jan 2008, at 04:08, elle wrote:> > Between the two of us, I would be the stupid one, not you :) > And I learn something new every day. > So, I can use :value to specify what shows in the field. > > But I now have a new question: I have all the states in an array and I > use an iterator to print out all the states. > Now, I want the customer''s state to be pre-selected, so, my logic says > to use something like that: > states.each do | state | %> > <option value="<%= state %>" > <%= if state == @cart.customer.ship_to_state then puts > ''selected="selected"'' end %> ><%= state %></option> > <% end %> > ...but this doesn''t work. It just prints the normal list of states, > with none selected. > What should I change? >Don''t use puts - <%= if state == @cart.customer.ship_to_state then ''selected="selected"'' end %> or even <%= ''selected="selected"'' if state == @cart.customer.ship_to_state%> But as it''s been said before there are helpers to take care of this. Fred> Elle > > > On Jan 9, 12:08 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Bah! I''m stupid. >> >> You should be specifying <%= text_field "order", "email", :value => @ >> cart.customer.email %> instead of: >> >> <%= text_field "order", "email", @cart.customer.email %> >> >> Be back later, banging my head against the desk. >> >> -- >> Ryan > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks guys and I agree about using a helper method. Would be better... but I tried that before and because I don''t know enough about rails just yet, I had trouble with it and resorted to this solution. How would you suggest I create a helper method? Elle On Jan 11, 10:25 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 11 Jan 2008, at 04:08, elle wrote: > > > > > > > Between the two of us, I would be the stupid one, not you :) > > And I learn something new every day. > > So, I can use :value to specify what shows in the field. > > > But I now have a new question: I have all the states in an array and I > > use an iterator to print out all the states. > > Now, I want the customer''s state to be pre-selected, so, my logic says > > to use something like that: > > states.each do | state | %> > > <option value="<%= state %>" > > <%= if state == @cart.customer.ship_to_state then puts > > ''selected="selected"'' end %> ><%= state %></option> > > <% end %> > > ...but this doesn''t work. It just prints the normal list of states, > > with none selected. > > What should I change? > > Don''t use puts - > <%= if state == @cart.customer.ship_to_state then > ''selected="selected"'' end %> > or even > <%= ''selected="selected"'' if state == @cart.customer.ship_to_state%> > > But as it''s been said before there are helpers to take care of this. > > Fred > > > Elle > > > On Jan 9, 12:08 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Bah! I''m stupid. > > >> You should be specifying <%= text_field "order", "email", :value => @ > >> cart.customer.email %> instead of: > > >> <%= text_field "order", "email", @cart.customer.email %> > > >> Be back later, banging my head against the desk. > > >> -- > >> Ryan--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---