From 3b424e341e1dda1f67b4461de089b76eb69bbc70 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Mon, 2 Feb 2009 14:06:47 +0000 Subject: [PATCH] Added availability date to product table --- app/views/products/edit.html.erb | 4 ++++ app/views/products/index.html.erb | 5 +++++ app/views/products/new.html.erb | 6 +++++- app/views/products/show.html.erb | 5 +++++ .../20090202124100_add_product_date_available.rb | 13 +++++++++++++ db/schema.rb | 5 +++-- public/stylesheets/depot.css | 4 ++++ 7 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20090202124100_add_product_date_available.rb diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb index 7aa095b..18efd55 100644 --- a/app/views/products/edit.html.erb +++ b/app/views/products/edit.html.erb @@ -19,6 +19,10 @@ <%= f.label :price %>
<%= f.text_field :price %>

+

+ <%= f.label :date_available %>
+ <%= f.date_select :date_available, :order => [:day, :month, :year] %> +

<%= f.submit "Update" %>

diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 1db53b8..6bb547a 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -14,6 +14,11 @@
<%= h product.title %>
<%= h truncate(product.description.gsub(/<.*?>/, ''), :length => 80) %>
+ <% if product.date_available.past? %> +
Available since <%= product.date_available %>
+ <% else %> +
Available from <%= product.date_available %>
+ <% end %> diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb index 90ef7f2..3762d07 100644 --- a/app/views/products/new.html.erb +++ b/app/views/products/new.html.erb @@ -19,7 +19,11 @@ <%= f.label :price %>
<%= f.text_field :price %>

-

+

+ <%= f.label :date_available %>
+ <%= f.date_select :date_available, :order => [:day, :month, :year] %> +

+

<%= f.submit "Create" %>

<% end %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 124ab77..fb3631e 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -18,6 +18,11 @@ <%=h @product.price %>

+

+ Date available: + <%=h @product.date_available %> +

+ <%= link_to 'Edit', edit_product_path(@product) %> | <%= link_to 'Back', products_path %> diff --git a/db/migrate/20090202124100_add_product_date_available.rb b/db/migrate/20090202124100_add_product_date_available.rb new file mode 100644 index 0000000..4c05607 --- /dev/null +++ b/db/migrate/20090202124100_add_product_date_available.rb @@ -0,0 +1,13 @@ +class AddProductDateAvailable < ActiveRecord::Migration + def self.up + add_column :products, :date_available, :date + + Product.update(1, :date_available => Time.utc(2008, 12, 25)) + Product.update(2, :date_available => Time.utc(2010, 12, 25)) + Product.update(3, :date_available => Time.utc(2009, 1, 1)) + end + + def self.down + remove_column :products, :date_available + end +end diff --git a/db/schema.rb b/db/schema.rb index b873092..2b20ee9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20090130111521) do +ActiveRecord::Schema.define(:version => 20090202124100) do create_table "products", :force => true do |t| t.string "title" @@ -17,7 +17,8 @@ ActiveRecord::Schema.define(:version => 20090130111521) do t.string "image_url" t.datetime "created_at" t.datetime "updated_at" - t.decimal "price", :precision => 8, :scale => 2, :default => 0.0 + t.decimal "price", :precision => 8, :scale => 2, :default => 0.0 + t.date "date_available" end end diff --git a/public/stylesheets/depot.css b/public/stylesheets/depot.css index bb9c8b5..62a2d67 100644 --- a/public/stylesheets/depot.css +++ b/public/stylesheets/depot.css @@ -40,6 +40,10 @@ h1 { margin: 0; } +#product-list .list-description .unavailable { + color: #f00; +} + #product-list .list-actions { font-size: x-small; text-align: right; -- 2.34.1