Order form: quantity fields

The situation is:

I have a Product table with data. I require a form. The form requires a
list of Products that have a text field opposite where the user can
specify a limitless amount of each product. The form will not relate to
a resource. It should send mail to a specified address with the
information of the order.

I’m unsure about the syntax I should use in the form, mailer model and
mailer views.

I need some assistance to get this working. I’m sure you can help,
whether it be directly or providing me with some documentation on this
particular topic.

On 6 July 2010 11:33, Pale H. [email protected] wrote:

I need some assistance to get this working. I’m sure you can help,
whether it be directly or providing me with some documentation on this
particular topic.

Start with the simplest bit and work up. Since you are not editing a
resource then use form_tag rather then form_for. Google and look at
the docs for how to use it (you will find many examples). Once you
have got a form to display then work out how to get the list of
products on it. Then work out how to get in the input fields, and so
on. Come back with questions when you get stuck.

Use a code control system such as git to manage your code so you can
easily experiment and go back to previous versions if you find
yourself up a blind alley.

Write tests as you go so that you know that the code works.

I presume you have worked through a number of tutorials on basic RoR
functionality, testing and so on. Even if they do not seem to be
directly applicable to your requirement you will learn a lot by doing
this.

Colin

Colin L. wrote:

On 6 July 2010 11:33, Pale H. [email protected] wrote:

I need some assistance to get this working. I’m sure you can help,
whether it be directly or providing me with some documentation on this
particular topic.

Start with the simplest bit and work up. Since you are not editing a
resource then use form_tag rather then form_for. Google and look at
the docs for how to use it (you will find many examples). Once you
have got a form to display then work out how to get the list of
products on it. Then work out how to get in the input fields, and so
on. Come back with questions when you get stuck.

Use a code control system such as git to manage your code so you can
easily experiment and go back to previous versions if you find
yourself up a blind alley.

Write tests as you go so that you know that the code works.

I presume you have worked through a number of tutorials on basic RoR
functionality, testing and so on. Even if they do not seem to be
directly applicable to your requirement you will learn a lot by doing
this.

Colin

Your input is appreciated, Colin.

I’ve got a basic form that generates a list of Products from the
database with a quantity field for each. The problem I have is
collecting this data to send. I’m not sure how the syntax for the form
and mailer models and views for this in particular, would appear.

Colin L. wrote:

On 6 July 2010 12:00, Pale H. [email protected] wrote:

have got a form to display then work out how to get the list of
functionality, testing and so on. Even if they do not seem to be
and mailer models and views for this in particular, would appear.

You seem to have snipped the original question so I have had to go
back to your initial email to see it, it is better not to snip so much
that the basic problem is lost.

You say you already have the form showing the list of products and
quantities. When you submit that form then the contents of the fields
will be passed in params[]. In the controller you can then pick up
the quantities. I am not sure exactly what you are having
difficulties with.

Colin

Example (this is one of the fields in the form. Others are being passed
fine. I understand that on submit, the contents of the parameters are
passed and we can then render those in the view appropriately):

Products <% for products in Product.all(:conditions => "display=1") %> <%= products.name %> <%= text_field :order, :product_quantity %> <% end %>

Obviously, the about renders a text field for each Product where the
user can enter the quantity the require opposite a Product name label.

Apologies if I’m being unclear.

On 6 July 2010 12:00, Pale H. [email protected] wrote:

have got a form to display then work out how to get the list of
functionality, testing and so on. Even if they do not seem to be
and mailer models and views for this in particular, would appear.
You seem to have snipped the original question so I have had to go
back to your initial email to see it, it is better not to snip so much
that the basic problem is lost.

You say you already have the form showing the list of products and
quantities. When you submit that form then the contents of the fields
will be passed in params[]. In the controller you can then pick up
the quantities. I am not sure exactly what you are having
difficulties with.

Colin

Colin L. wrote:

On 6 July 2010 12:20, Pale H. [email protected] wrote:

Products <% for products in Product.all(:conditions => "display=1") %> <%= products.name %> <%= text_field :order, :product_quantity %> <% end %>

Obviously, the about renders a text field for each Product where the
user can enter the quantity the require opposite a Product name label.

Is that inside a form_tag? It should be text_field_tag I think.

Colin

The other text_fields I’m using are working fine with this method.

On 6 July 2010 12:58, Pale H. [email protected] wrote:

user can enter the quantity the require opposite a Product name label.

Is that inside a form_tag? It should be text_field_tag I think.

Colin

The other text_fields I’m using are working fine with this method.

You did not answer whether it is inside a form_for or form_tag.
Please show the complete form code.

Colin

On 6 July 2010 12:20, Pale H. [email protected] wrote:

You say you already have the form showing the list of products and

Products <% for products in Product.all(:conditions => "display=1") %> <%= products.name %> <%= text_field :order, :product_quantity %> <% end %>

Obviously, the about renders a text field for each Product where the
user can enter the quantity the require opposite a Product name label.

Is that inside a form_tag? It should be text_field_tag I think.

Colin

http://pastie.org/1032538

On 6 July 2010 13:13, Pale H. [email protected] wrote:

http://pastie.org/1032538

Once again you have snipped all the content so this will make no sense
to anyone reading it without referring back to previous messages.

What is this :order that you are referencing? Check the docs on
text_field and you will find that it is designed to be used with
attribute of an object. You have specified the product_quantity of
the order object. Since you are attempting to pass a number of
different quantities each must have a different name. In fact you
probably want to pass them as an array. As I said before I would use
text_field_tag in this situation.

Also I would suggest using form_for if you do have an order model, for
the attributes.

Actually I think maybe it would be worthwhile knowing what your model
relationships are. If you have the model relationships right then you
can do clever things with nested forms. See
#196 Nested Model Form Part 1 - RailsCasts for
example.

Colin

Colin L. wrote:

On 6 July 2010 13:13, Pale H. [email protected] wrote:

http://pastie.org/1032538

Once again you have snipped all the content so this will make no sense
to anyone reading it without referring back to previous messages.

Sorry, but they can always refer to this forum topic to view the
previous messages. I don’t know which mailing list you’re posting from
but it should have the facility to view the original post.

What is this :order that you are referencing? Check the docs on
text_field and you will find that it is designed to be used with
attribute of an object. You have specified the product_quantity of
the order object. Since you are attempting to pass a number of
different quantities each must have a different name. In fact you
probably want to pass them as an array. As I said before I would use
text_field_tag in this situation.

Also I would suggest using form_for if you do have an order model, for
the attributes.

Actually I think maybe it would be worthwhile knowing what your model
relationships are. If you have the model relationships right then you
can do clever things with nested forms. See
#196 Nested Model Form Part 1 - RailsCasts for
example.

Colin

As I’ve said, this form isn’t related to a model. It simply collects the
parameters and mails them.

I want the output to be similar to:

Product A:
Product B:
Product C:

On 6 July 2010 14:35, Pale H. [email protected] wrote:

Colin L. wrote:

On 6 July 2010 13:13, Pale H. [email protected] wrote:

http://pastie.org/1032538

Once again you have snipped all the content so this will make no sense
to anyone reading it without referring back to previous messages.

Sorry, but they can always refer to this forum topic to view the
previous messages. I don’t know which mailing list you’re posting from
but it should have the facility to view the original post.

This is a mailing list, not a forum. You may be viewing it elsewhere
but the original is the mailing list.
http://groups.google.com/group/rubyonrails-talk

What is this :order that you are referencing? Check the docs on
text_field and you will find that it is designed to be used with
attribute of an object. You have specified the product_quantity of
the order object. Since you are attempting to pass a number of
different quantities each must have a different name. In fact you
probably want to pass them as an array. As I said before I would use
text_field_tag in this situation.

You have not responded to the above

Also I would suggest using form_for if you do have an order model, for
the attributes.

You have not responded to the above

Actually I think maybe it would be worthwhile knowing what your model
relationships are. If you have the model relationships right then you
can do clever things with nested forms. See
#196 Nested Model Form Part 1 - RailsCasts for
example.

You have not responded to the above

Colin

As I’ve said, this form isn’t related to a model. It simply collects the
parameters and mails them.

In that case what is :order?

You have not responded to my comments above suggesting where you may
be going wrong.

Colin

On 6 July 2010 15:23, Pale H. [email protected] wrote:

Colin

I was wrong to use :order because this is not a model form.

So, http://pastie.org/1032691 should look more appropriate.

What about my other comments (snipped again I notice, I will go back
to the previous email to get them):

Since you are attempting to pass a number of
different quantities each must have a different name. In fact you
probably want to pass them as an array.

If you look at the html you should see that all the quantity input
fields have the same name so they will all be in the same parameter in
params which is no good. Google for text_field_tag array to find
examples of how to do pass an array of values.

I still don’t understand why you have not got an order model (it does
not have to map to a table in the db). Where are you putting the
business logic for an order if you have not got an order model?

Colin

Colin L. wrote:

Actually I think maybe it would be worthwhile knowing what your model
relationships are. �If you have the model relationships right then you
can do clever things with nested forms. �See
#196 Nested Model Form Part 1 - RailsCasts for
example.

You have not responded to the above

Colin

As I’ve said, this form isn’t related to a model. It simply collects the
parameters and mails them.

In that case what is :order?

You have not responded to my comments above suggesting where you may
be going wrong.

Colin

I was wrong to use :order because this is not a model form.

So, http://pastie.org/1032691 should look more appropriate.