Skip to content

Instantly share code, notes, and snippets.

@ryanvermooten
Created February 22, 2015 20:20
Show Gist options
  • Select an option

  • Save ryanvermooten/69e779b9d938df9aa03c to your computer and use it in GitHub Desktop.

Select an option

Save ryanvermooten/69e779b9d938df9aa03c to your computer and use it in GitHub Desktop.
<h1>Listing orders</h1>
</div>
<table>
<thead>
<tr>
<th> </th>
<th> Template used </th>
<th> Special Notes </th>
<th> Date due </th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @orders.each do |t| %>
<tr>
<td><%= t.customer %></td>
<td><%= t.templates %></td>
<td><%= t.special_notes %></td>
<td><%= t.due_at %></td>
<div id="orders">
<div class ="artwork">
<%= image_tag t.image_url(:thumb).to_s %>
</div>
</div>
</tr>
<% end %>
</tbody>
</table>
<%= link_to 'New Order', new_order_path %>
class Order < ActiveRecord::Base
include PublicActivity::Model
tracked
has_and_belongs_to_many :users
belongs_to :customer
has_and_belongs_to_many :templates, through: :orders_templates
mount_uploader :image, ImageUploader
def due_at_string
due_at.to_s(:db)
end
def due_at_string=(due_at_str)
self.due_at = Time.parse(due_at_str)
end
end
class OrdersController < ApplicationController
before_filter :prepare_customers
#before_action :set_order, only: [:show, :edit, :update, :destroy]
respond_to :html
def index
@orders = Order.all
#respond_with(@orders)
end
def show
@order= Order.find(params[:id])
@customer = Customer.all
respond_with(@order)
end
def new
@order = Order.new
@template = Template.all
@customer = Customer.all
respond_with(@order)
end
def edit
@order= Order.find(params[:id])
@customer = @order.customer
@template = @order.templates
end
def create
@order = Order.new(order_params)
flash[:notice] = 'Order was successfully created.' if @order.save
respond_with(@order)
end
def update
flash[:notice] = 'Order was successfully updated.' if @order.update(order_params)
respond_with(@order)
end
def destroy
@order.destroy
respond_with(@order)
end
private
def import
Order.import(params[:file])
redirect_to root_url, notice: "products imported"
end
def prepare_customers
@customers = Customer.all
end
def set_order
@order = Order.find(params[:id])
end
def order_params
params.require(:order).permit(:customer_id, :special_notes, :image, :due_at, :template_ids => [])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment