Order form: quantity fields

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 Law wrote:

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 Law 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):

<p>
<label for="order_products">Products</label>
<% for products in Product.all(:conditions => "display=1") %>
<%= products.name %>&nbsp;<%= text_field :order, :product_quantity %>
<% end %>
</p>

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.

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

Colin

Colin Law wrote:

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

Colin

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
http://railscasts.com/episodes/196-nested-model-form-part-1 for
example.

Colin

Colin Law 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
http://railscasts.com/episodes/196-nested-model-form-part-1 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: <quantity>
Product B: <quantity>
Product C: <quantity>

Colin Law 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
http://railscasts.com/episodes/196-nested-model-form-part-1 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

Colin Law 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
http://railscasts.com/episodes/196-nested-model-form-part-1 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.

Colin Law 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
http://railscasts.com/episodes/196-nested-model-form-part-1 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.

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