def self.find_products_for_sale
find(:all,
- :conditions => "date_available <= now()",
+ :conditions => "date_available <= now() and (date_available_until is null or date_available_until >= now())",
:order => :title)
end
<%= f.label :date_available %><br />
<%= f.date_select :date_available, :order => [:day, :month, :year] %>
</p>
+ <p>
+ <%= f.label :date_available_until %><br />
+ <%= f.date_select :date_available_until, :order => [:day, :month, :year], :include_blank => true %>
+ </p>
<p>
<%= f.submit "Update" %>
</p>
<% else %>
<dd class="unavailable">Available from <%= product.date_available %></dd>
<% end %>
+ <% if not product.date_available_until.nil? %>
+ <% if product.date_available_until.future? %>
+ <dd>Available until <%= product.date_available_until %></dd>
+ <% else %>
+ <dd class="unavailable">Unavailable since <%= product.date_available_until %></dd>
+ <% end %>
+ <% end %>
</dl>
</td>
<%= f.label :date_available %><br />
<%= f.date_select :date_available, :order => [:day, :month, :year] %>
</p>
+ <p>
+ <%= f.label :date_available_until %><br />
+ <%= f.date_select :date_available_until, :order => [:day, :month, :year], :include_blank => true %>
+ </p>
<p>
<%= f.submit "Create" %>
</p>
<%=h @product.date_available %>
</p>
+<p>
+ <b>Available until:</b>
+ <%=h @product.date_available_until %>
+</p>
<%= link_to 'Edit', edit_product_path(@product) %> |
<%= link_to 'Back', products_path %>
</p>
},
:image_url => '/images/daisy.gif',
- :price => 5.00,
+ :price => 4.99,
:date_available => Time.utc(2011, 7, 1)
)
</p>
},
:image_url => '/images/can-of-air.jpg',
- :price => 5000.00,
+ :price => 4999.95,
:date_available => Time.utc(2009, 1, 1)
)
end
--- /dev/null
+class AddDateAvilableUntilToProduct < ActiveRecord::Migration
+ def self.up
+ add_column :products, :date_available_until, :date
+ Product.reset_column_information
+ end
+
+ def self.down
+ remove_column :products, :date_available_until
+ end
+end
--- /dev/null
+class AddMoreTestData < ActiveRecord::Migration
+ def self.up
+ Product.create(:title => 'Rainbow',
+ :description =>
+ %{<p>What could be better than a beautiful rainbow to brighten up your
+ day? Experience the wonder of light and water in all its glory.
+ </p>
+ <p>Due to metreological variations, the rainbow you receive may
+ differ slightly from the one shown here.
+ </p>
+ <p>(Terminal gold not included.)
+ </p>
+ },
+ :image_url => '/images/rainbow.jpg',
+ :price => 17.99,
+ :date_available => Time.utc(2008, 12, 31),
+ :date_available_until => Time.utc(2009, 1, 1)
+# :available_until => 'fred'
+# :au => Time.utc(2008, 12, 31)
+ )
+
+ box = Product.find(3)
+ box.update_attribute(:date_available_until, Time.utc(2010, 7, 1))
+# box.update_attribute(:available_until, 'tom')
+# box.update_attribute(:au, Time.utc(2010, 7, 1))
+ end
+
+ def self.down
+ Product.delete_all(["title = ?", 'Rainbow'])
+ end
+end
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090202163608) do
+ActiveRecord::Schema.define(:version => 20090226212307) do
create_table "products", :force => true do |t|
t.string "title"
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"
+ t.date "date_available_until"
end
+ create_table "sessions", :force => true do |t|
+ t.string "session_id", :null => false
+ t.text "data"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
+ add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
+
end