Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

modified store controller to load products

  • Loading branch information...
commit 654573fed2e31268b8c99dc4cde17ab23ab969f4 1 parent 741945d
@florida authored
View
17 app/assets/stylesheets/application.css
@@ -1,17 +0,0 @@
-/*
- * This is a manifest file that'll be compiled into application.css, which will include all the files
- * listed below.
- *
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
- *
- * You're free to add application-wide styles to this file and they'll appear at the top of the
- * compiled file, but it's generally better to create a new file per style scope.
- *
- *= require_self
- *= require_tree .
- */
-
- body{
- background-image: url(bg.png);
- }
View
83 app/controllers/products_controller.rb
@@ -1,83 +0,0 @@
-class ProductsController < ApplicationController
- # GET /products
- # GET /products.json
- def index
- @products = Product.all
-
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @products }
- end
- end
-
- # GET /products/1
- # GET /products/1.json
- def show
- @product = Product.find(params[:id])
-
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @product }
- end
- end
-
- # GET /products/new
- # GET /products/new.json
- def new
- @product = Product.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @product }
- end
- end
-
- # GET /products/1/edit
- def edit
- @product = Product.find(params[:id])
- end
-
- # POST /products
- # POST /products.json
- def create
- @product = Product.new(params[:product])
-
- respond_to do |format|
- if @product.save
- format.html { redirect_to @product, notice: 'Product was successfully created.' }
- format.json { render json: @product, status: :created, location: @product }
- else
- format.html { render action: "new" }
- format.json { render json: @product.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # PUT /products/1
- # PUT /products/1.json
- def update
- @product = Product.find(params[:id])
-
- respond_to do |format|
- if @product.update_attributes(params[:product])
- format.html { redirect_to @product, notice: 'Product was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: "edit" }
- format.json { render json: @product.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # DELETE /products/1
- # DELETE /products/1.json
- def destroy
- @product = Product.find(params[:id])
- @product.destroy
-
- respond_to do |format|
- format.html { redirect_to products_url }
- format.json { head :no_content }
- end
- end
-end
View
1  app/controllers/store_controller.rb
@@ -1,5 +1,6 @@
class StoreController < ApplicationController
def index
+ @products = Product.available_items
end
end
View
5 app/models/product.rb
@@ -1,5 +1,5 @@
class Product < ActiveRecord::Base
- attr_accessible :description, :name, :price, :stock_no, :image_url
+ attr_accessible :description, :name, :price, :stock_no, :image_url, :available
has_many :lineitems
validates :description, :presence => true
validates :name, :presence => true
@@ -9,7 +9,8 @@ class Product < ActiveRecord::Base
def self.available_items
-
+ find(:all,
+ :conditions => { :available => true} )
end
end
View
33 app/views/orders/_form.html.erb
@@ -1,33 +0,0 @@
-<%= form_for(@order) do |f| %>
- <% if @order.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@order.errors.count, "error") %> prohibited this order from being saved:</h2>
-
- <ul>
- <% @order.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <div class="field">
- <%= f.label :first_name %><br />
- <%= f.text_field :first_name %>
- </div>
- <div class="field">
- <%= f.label :last_name %><br />
- <%= f.text_field :last_name %>
- </div>
- <div class="field">
- <%= f.label :email %><br />
- <%= f.text_field :email %>
- </div>
- <div class="field">
- <%= f.label :address %><br />
- <%= f.text_field :address %>
- </div>
- <div class="actions">
- <%= f.submit %>
- </div>
-<% end %>
View
6 app/views/orders/edit.html.erb
@@ -1,6 +0,0 @@
-<h1>Editing order</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', @order %> |
-<%= link_to 'Back', orders_path %>
View
29 app/views/orders/index.html.erb
@@ -1,29 +0,0 @@
-<h1>Listing orders</h1>
-
-<table>
- <tr>
- <th>First name</th>
- <th>Last name</th>
- <th>Email</th>
- <th>Address</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-
-<% @orders.each do |order| %>
- <tr>
- <td><%= order.first_name %></td>
- <td><%= order.last_name %></td>
- <td><%= order.email %></td>
- <td><%= order.address %></td>
- <td><%= link_to 'Show', order %></td>
- <td><%= link_to 'Edit', edit_order_path(order) %></td>
- <td><%= link_to 'Destroy', order, method: :delete, data: { confirm: 'Are you sure?' } %></td>
- </tr>
-<% end %>
-</table>
-
-<br />
-
-<%= link_to 'New Order', new_order_path %>
View
5 app/views/orders/new.html.erb
@@ -1,5 +0,0 @@
-<h1>New order</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Back', orders_path %>
View
25 app/views/orders/show.html.erb
@@ -1,25 +0,0 @@
-<p id="notice"><%= notice %></p>
-
-<p>
- <b>First name:</b>
- <%= @order.first_name %>
-</p>
-
-<p>
- <b>Last name:</b>
- <%= @order.last_name %>
-</p>
-
-<p>
- <b>Email:</b>
- <%= @order.email %>
-</p>
-
-<p>
- <b>Address:</b>
- <%= @order.address %>
-</p>
-
-
-<%= link_to 'Edit', edit_order_path(@order) %> |
-<%= link_to 'Back', orders_path %>
View
33 app/views/products/_form.html.erb
@@ -1,33 +0,0 @@
-<%= form_for(@product) do |f| %>
- <% if @product.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
-
- <ul>
- <% @product.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <div class="field">
- <%= f.label :name %><br />
- <%= f.text_field :name %>
- </div>
- <div class="field">
- <%= f.label :description %><br />
- <%= f.text_area :description %>
- </div>
- <div class="field">
- <%= f.label :price %><br />
- <%= f.text_field :price %>
- </div>
- <div class="field">
- <%= f.label :stock_no %><br />
- <%= f.number_field :stock_no %>
- </div>
- <div class="actions">
- <%= f.submit %>
- </div>
-<% end %>
View
6 app/views/products/edit.html.erb
@@ -1,6 +0,0 @@
-<h1>Editing product</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', @product %> |
-<%= link_to 'Back', products_path %>
View
29 app/views/products/index.html.erb
@@ -1,29 +0,0 @@
-<h1>Listing products</h1>
-
-<table>
- <tr>
- <th>Name</th>
- <th>Description</th>
- <th>Price</th>
- <th>Stock no</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-
-<% @products.each do |product| %>
- <tr>
- <td><%= product.name %></td>
- <td><%= product.description %></td>
- <td><%= product.price %></td>
- <td><%= product.stock_no %></td>
- <td><%= link_to 'Show', product %></td>
- <td><%= link_to 'Edit', edit_product_path(product) %></td>
- <td><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></td>
- </tr>
-<% end %>
-</table>
-
-<br />
-
-<%= link_to 'New Product', new_product_path %>
View
5 app/views/products/new.html.erb
@@ -1,5 +0,0 @@
-<h1>New product</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Back', products_path %>
View
25 app/views/products/show.html.erb
@@ -1,25 +0,0 @@
-<p id="notice"><%= notice %></p>
-
-<p>
- <b>Name:</b>
- <%= @product.name %>
-</p>
-
-<p>
- <b>Description:</b>
- <%= @product.description %>
-</p>
-
-<p>
- <b>Price:</b>
- <%= @product.price %>
-</p>
-
-<p>
- <b>Stock no:</b>
- <%= @product.stock_no %>
-</p>
-
-
-<%= link_to 'Edit', edit_product_path(@product) %> |
-<%= link_to 'Back', products_path %>
View
11 app/views/store/_product.html.erb
@@ -0,0 +1,11 @@
+<section class="product">
+ <header><%= product.name %></header>
+ <section class="product_image">
+ <%= image_tag product.image_url, :width => '20%' if product.image_url.present? %>
+ </section>
+ <section class="product_info">
+ <span class="label">Price</span>
+ <span class="value"><%= product.price %></span>
+ </section>
+ <footer><%= link_to 'Buy Now', '#' %></footer>
+</section>
View
3  app/views/store/index.html.erb
@@ -1,2 +1 @@
-<h1>Store#index</h1>
-<p>Find me in app/views/store/index.html.erb</p>
+<%= render :partial => 'product', :collection => @products, :as => 'product' %>
Please sign in to comment.
Something went wrong with that request. Please try again.