Created
September 15, 2012 00:53
-
-
Save andyjbas/3725875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# orders show | |
<%= @order.status %> | |
Line_items: | |
<br> | |
<% @order.line_items.each do |item| %> | |
<%= item.notes %>, <%= item.units %> | |
<% end %> | |
# orders create action | |
def create | |
@order = Order.new(params[:order]) | |
LineItem.create(params[:order][:line_items_attributes][0]) | |
respond_to do |format| | |
if @order.save | |
format.html { redirect_to @order, notice: 'Order was successfully created.' } | |
format.json { render json: @order, status: :created, location: @order } | |
else | |
format.html { render action: "new" } | |
format.json { render json: @order.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# order form partial | |
<%= form_for(@order) do |f| %> | |
<% if @order.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@order.errors.count, "error") %> prohibited this order from being saved:</h2> | |
<ul> | |
<% @order.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<%= f.text_field :status %> | |
<%= f.fields_for :line_items do |l| %> | |
<%= l.label :notes %> | |
<%= l.text_field :notes %> | |
<%= l.label :units %> | |
<%= l.text_field :units %> | |
<% end %> | |
<%= f.submit %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment