-
Notifications
You must be signed in to change notification settings - Fork 0
/
Development Doc.txt
322 lines (222 loc) · 8.53 KB
/
Development Doc.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
This Document contains notes on the development of my music store.
This will be used to note code that was entered or to play with as well as any other ideas.
********************10/18/2011***********************************
Scaffold generation:
rails generate scaffold Product title:string artist:string album:string description:text image_url:string price:decimal
Read Chapter 6 and did the basic creation of a new rails app and set up my data base
made the suggested change to my 20111018195858_create_products.rb(Music_Store/db/migrate)
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.string :title
t.string :artist
t.string :album
t.text :description
t.string :image_url
t.decimal :price, precision => 8, :scale => 2
t.timestamps
end
end
def self.down
drop_table :products *****investigate this option when development progresses.
end
end
Began building my Seeds file with sample titles from Linkin Park.
Product.delete_all
Product.create(:title => 'Burning In The Skies',
:artist => 'Linkin Park',
:album => 'A Thousand Suns',
:description =>
%{<p>
Length - 4:13
Genre Alternative Rock
Composer - Linkin Park
</p>},
:image_url => '/images/wd4d.jpg',
:price => 42.95)
# . . .
Start here next time and add more titles and download album cover picture.
*****************************11/4/2011***************************************************************************
Finished adding sample tracks to my seed db seed file and added the cover image.
Adding the depot.css file to public/stylesheets directory. *****************Need to play with this***************
Added code below to public/depot.css file to play with displaying title, artist and album
#product_list .list_title{
width: 20%;
}
#product_list .list_title dl{
margin: 0;
}
#prodct_list .list_title dt{
color: #fff;
font-weight: bold ;
font-size: small;
}
#product_list .list_artist{
width: 20%;
}
#product_list .list_artist dl{
margin: 0;
}
#prodct_list .list_artist dt{
color: #fff;
font-weight: bold ;
font-size: small;
}
#product_list .list_album{
width: 20%;
}
#product_list .list_album dl{
margin: 0;
}
#prodct_list .list_album dt{
color: #fff;
font-weight: bold;
font-size: small;
}
needed to move images folder from /app/assets/images to /public/
Created Git repository PazStore and made my first commit and added my files
Added Validation for title....description, price, and Image URL
Start at chapter 7 pg 80 when starting again.
**************************************11/7/2011 Unit Testing**************************************************************
Having issues doing the units tests.... *****come back to this later or try out cucumber testing *******
Had success with the following test.
test"product price must be positive" do
product = Product.new(:title => "My Song",
:artist => "My artist",
:album => "MyAlbum",
:description => "yyy",
:image_url => "zzz.jpg")
product.price = -1
assert product.invalid?
assert_equal "must be greater than or equal to 0.01",
product.errors[:price].join('; ')
product.price = 0
assert product.invalid?
assert_equal "must be greater than or equal to 0.01",
product.errors[:price].join('; ')
product.price = 1
assert product.valid?
end
had Success with all unit tests except for test "product attributes must not be empty"
****************************Catalog Listing******************************
created new controller with:
rails generate controller store index
updated routes to go to store index in /config/routes:
root :to => 'store#index', :as => 'store'
had to remove public/index.html by git rm public/index.html (using git to manage source code)
updated store_controller to show all products:
class StoreController < ApplicationController
def index
@products = Product.all
end
end
Displaying products in alphabetical order in /app/modes/product by: *********come back and play with this******
class Product < ActiveRecord::Base
default_scope :order => 'title' *****possible to do it by artist or song****
Added the following to display products on page in app/store/index.html.erb
<% if notice %>
<p id = "notice"><%= notice %></p>
<% end %>
<h1> Your Music Catalog</h1>
<% @products.each do |product| %>
<div class="entry">
<%= image_tag(product.image_url) %>
<h3> <%= product.title %></h3>
<h5> <%= product.artist %></h5>
<h6> <%= product.album %></h6>
<div class="price_line">
<span class="price"><%= product.price %></span>
</div>
</div>
<% end %>
improved display by editing /app/views/layouts/application.html.erb with:
<!DOCTYPE html>
<html>
<head>
<title>PazStore</title>
<%= stylesheet_link_tag "application" %>
<%= stylesheet_link_tag "depot", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body id="store">
<div id="banner">
<%= image_tag("logo.jpg") %>
<%= @page_title || "Paz Music Store" %>
</div>
<div id = "columns">
<div id = "side">
<a href= "http://www....">Home</a><br />
<a href="mailto:nmeliasp@unm.edu">Contact Us</a><br />
</div>
<div id="main">
<%= yield %>
</div>
</div>
</body>
</html>
Had to place logo.jpg in /public/assets
Updated depot.css file with /* Styles for Main Page */****come back and play with colors and layouts
added to app/views/store/index.html.erb for formating of te price
<span class="price"><%= number_to_currency(product.price) %></span>
**********Cart Creation*****************************
generated cart with and migrated it to db:
rails generate scaffold cart
edited app/controllers/application_controller to store and index a cart id
class ApplicationController < ActionController::Base
protect_from_forgery
private
def current_cart
Cart.find(session[:cart_id])
rescue ActiveRecord::RecordNotFound
cart = Cart.create
session[:cart_id] = cart.id
cart
end
generated line_items and migrated to db:
rails generate scaffold line_item product_id:integer cart_id:integer
start on pg 103 to continue.
*************************************11/9/2011*******************************************************************
*****Connecting Products to Carts**********
Connected line_items to the cart and added a destroy dependency
class Cart < ActiveRecord::Base
has_many :line_items, :dependent => destroy
end
Connected line_items to product and cart
class LineItem < ActiveRecord::Base
belongs_to :product
belongs_to :cart
end
Defined that product has many line items and check if a line is being referenced before being destroyed
class Product < ActiveRecord::Base
default_scope :order => 'title'
has_many :line_items
before_destroy :ensure_not_referenced_by_any_line_item
#.....
private
#ensure that there are no line items referencing this product
def ensure_not_referenced_by_any_line_item
if line_items.empty?
return true
else
errors.add(:base, 'Line Items Present')
return false
end
end
***********Adding a button*********
added line to create the button in /app/views/store/index.html.erb:
<%= button_to 'Add to Cart', line_items_path(:product_id => product) %>
the following CSS puts the botton next to the price
#store .entry form, #store .entry form div{
display: inline;
updated /app/controllers/line_items_controller so the shopping cart can find the current session, add the selected product to that cart, and display that contents.
def create
@cart = current_cart
product = Product.find(params[:product_id])
@line_item = @cart.line_items.build(:product => product)
respond_to do |format|
if @line_item.save
format.html { redirect_to @line_item.cart, notice: 'Line item was successfully created.' }
format.json { render json: @line_item, status: :created, location: @line_item }
updated app/views/carts/show.html.erb to display the contents of the cart.
start on chapter 10 pg 111 when continuing