Just think about how to create an order form that will (from the user's point of view):
- Allow adding multiple items.
- Each item has a drop-down list of "Name", "Job Type" and "File Download".
- User can add or remove items.
- The user must provide at least one item.
- All items must be checked (for example: Name, JobType and File).
- When he clicks the submit button, an order must be created with all the elements in it.
So, the model is as follows: User -1---*-Order-1---*- OrderItem-*--1-JobType. Furthermore, OrderItem includes a number of attributes, for example name, file.
Now I would like to have a skinny controller as possible. Better with standard code:
class OrdersController < ApplicationController
def create
@order = Order.new(params[:order])
if @order.save
redirect_to account_url
else
flash.now[:error] = "Could not save Order"
render :action => "new"
end
end
end
: , , , ?
JavaScript, (, ).
, , , .
<input type='text' name='order[order_items[name[]]][]' />
<select name='order[order_items[job_type[]]][]'>...</select>
<input type='file' name='order[order_items[file[]]][]' />
, JS.
:
, - ( , - GitHub).
, , .
,
.