Permalink
Browse files

added an image url column, added validations

  • Loading branch information...
1 parent 078606b commit 353e1aa6222d2782972346be8df6d12ac9b0a9d9 @florida committed Nov 14, 2012
@@ -44,7 +44,7 @@ def create
respond_to do |format|
if @order.save
- format.html { redirect_to @order, notice: 'Order was successfully created.' }
+ format.html { redirect_to admin_order_path(@order), notice: 'Order was successfully created.' }
format.json { render json: @order, status: :created, location: @order }
else
format.html { render action: "new" }
@@ -60,7 +60,7 @@ def update
respond_to do |format|
if @order.update_attributes(params[:order])
- format.html { redirect_to @order, notice: 'Order was successfully updated.' }
+ format.html { redirect_to admin_order_path(@order), notice: 'Order was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
@@ -76,7 +76,7 @@ def destroy
@order.destroy
respond_to do |format|
- format.html { redirect_to orders_url }
+ format.html { redirect_to admin_orders_url }
format.json { head :no_content }
end
end
@@ -44,7 +44,7 @@ def create
respond_to do |format|
if @product.save
- format.html { redirect_to @product, notice: 'Product was successfully created.' }
+ format.html { redirect_to admin_product_path(@product), notice: 'Product was successfully created.' }
format.json { render json: @product, status: :created, location: @product }
else
format.html { render action: "new" }
@@ -60,7 +60,7 @@ def update
respond_to do |format|
if @product.update_attributes(params[:product])
- format.html { redirect_to @product, notice: 'Product was successfully updated.' }
+ format.html { redirect_to admin_product_path(@product), notice: 'Product was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
@@ -76,7 +76,7 @@ def destroy
@product.destroy
respond_to do |format|
- format.html { redirect_to products_url }
+ format.html { redirect_to admin_products_url }
format.json { head :no_content }
end
end
View
@@ -1,4 +1,10 @@
class Order < ActiveRecord::Base
- attr_accessible :address, :email, :first_name, :last_name
+ ORDER_STATUS = ["Shipped", "Pending", "Order Requested"]
+ attr_accessible :address, :email, :first_name, :last_name, :status
has_many :lineitems
+ validates :address, :presence => true
+ validates :email, :presence => true, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create }
+ validates :first_name, :presence => true
+ validates :last_name, :presence => true
+ validates_inclusion_of :status, :in => ORDER_STATUS
end
View
@@ -1,4 +1,8 @@
class Product < ActiveRecord::Base
- attr_accessible :description, :name, :price, :stock_no
+ attr_accessible :desccription, :name, :price, :stock_no
has_many :lineitems
+ validates :description, :presence => true
+ validates :name, :presence => true
+ validates :price, :numericality => true, :presence => true
+ validates :stock_no, :numericality => { :only_integer => true }
end
@@ -1,4 +1,4 @@
-<%= form_for(@order) do |f| %>
+<%= form_for [:admin, @order] do |f| %>
<% if @order.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@order.errors.count, "error") %> prohibited this order from being saved:</h2>
@@ -19,7 +19,7 @@
<td><%= order.address %></td>
<td><%= link_to 'Show', admin_order_path(order) %></td>
<td><%= link_to 'Edit', edit_admin_order_path(order) %></td>
- <td><%= link_to 'Destroy', order, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ <td><%= link_to 'Destroy', admin_order_path(order), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
@@ -1,4 +1,4 @@
-<%= form_for(@product) do |f| %>
+<%= form_for [:admin, @product] do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
View
@@ -1,4 +1,6 @@
Elmorfstore::Application.routes.draw do
+ get "store/index"
+
# get "store/index"
root :to => 'store#index'
@@ -0,0 +1,5 @@
+class AddImageUrlColumnToProducts < ActiveRecord::Migration
+ def change
+ add_column :products, :image_url, :string
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121113164059) do
+ActiveRecord::Schema.define(:version => 20121114035955) do
create_table "lineitems", :force => true do |t|
t.integer "product_id"
@@ -42,6 +42,16 @@
t.integer "stock_no"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.string "image_url"
+ end
+
+ create_table "users", :force => true do |t|
+ t.string "username", :null => false
+ t.string "email"
+ t.string "crypted_password"
+ t.string "salt"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
end

0 comments on commit 353e1aa

Please sign in to comment.