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?
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
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?
order
<%= text_field :order, :email %>
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.
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:
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?
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?
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.
Actually this gave me an error, but when changing it to:
… but the email is valid.
Then you can get the email from that user record.
Would Rails know to find that info? and would it still know
–
Ryan B.http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.
–
Ryan B.
Feel free to add me to MSN and/or GTalk as this email.
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 %>
<% end %>
…but this doesn’t work. It just prints the normal list of states,
with none selected.
What should I change?
<option value="<%= state %>"
<%= if state == @cart.customer.ship_to_state then puts
‘selected=“selected”’ end %> ><%= state %>
<% 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.
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?