Just thinking about the best way to build an Order form that would (from user-perspective):
So the model looks like: User -1---*-Order-1---*- OrderItem-*--1-JobType. Additionally OrderItem includes number of attributes, let's say name, file.
Now I would like to have as skinny controller as possible. Better with the 'standard' code like:
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
The most interesting thing is how a view should look like so that rails automatically binds all the values posted to the correct objects?
For now I don't worry about degradation from JavaScript, but rather the template for the items to be added and linking all that with the validation (probably as a partial).
I expect a template to look like the one below, but not sure.
<input type='text' name='order[order_items[name[]]][]' />
<select name='order[order_items[job_type[]]][]'>...</select>
<input type='file' name='order[order_items[file[]]][]' />
I have to clone this template in order to add item using JS.
So the answer should:
Ideally I would like to see a sample if somebody knows one (maybe somewhere on GitHub).
And the last note, please, check your solutions before posting.
Thanks,
Dmitriy.
Not answering the question directly, but here are some sources to get you there:
On a personal note. Your question comes across as asking for someone to do your work for you. I would gladly post an answer to cover all your needs if I was on the clock.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With