Commit cafc98c4 authored by Chanelle Lunod's avatar Chanelle Lunod

Initial commit

parent d5c4efc5
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the Orders controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the Supplies controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class CommentsController < ApplicationController class CommentsController < ApplicationController
def new def new
@product = Product.find_by(id: params[:product_id])
@comment = @product.comments.new
end
def create
@product = Product.find_by(id: params[:product_id])
@comment = @product.comments.new(comment_params)
@comment.user = current_user
if @comment.save
redirect_to transaction_path(@product), notice: "Comment has been added."
else
render 'new'
end
end
private
def comment_params
params.require(:comment).permit!
end end
end end
class OrdersController < ApplicationController
def new
@orders = Order.new
end
def create
@orders = Order.new(product_params)
if @orders.save
redirect_to products_path, notice: "You have successfully placed a new order"
else
render 'new'
end
end
def show
if params [:status] == 'Active'
@products = Product.Active
else
@products = Product.Inactive
end
end
end
\ No newline at end of file
class SuppliesController < ApplicationController
def index
@products = Product.all
end
def new
@supplies = Supply.new
end
def create
@supplies = Supply.new(product_params)
if @supplies.save
redirect_to products_path, notice: "You have successfully added a new supply."
else
render 'new'
end
end
def show
if params [:status] == 'Active'
@products = Product.Active
else
@products = Product.Inactive
end
end
end
\ No newline at end of file
class TransactionsController < ApplicationController
before_action :authenticate_user!
def index
@products = Product.all
end
def display
@product = Product.find_by(id: params[:id])
end
def new
@product.order = Order.new
@products.supply = Supply.new
end
def order
@product.order = Order.new(transaction_params)
if @product.order.save
redirect_to transaction_path, notice: "You have successfuly placed a new order."
else
render 'new'
end
end
def supply
@product.supply = Supply.new(transaction_params)
if @product.supply.save
redirect_to transaction_path, notice: "You have successfully placed a new supply."
else
render 'new'
end
end
private
def product_params
params.require(:product).permit!
end
end
\ No newline at end of file
module OrdersHelper
end
module SuppliesHelper
end
class Comment < ApplicationRecord class Comment < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :post belongs_to :product
end end
class Product < ApplicationRecord class Product < ApplicationRecord
has_many :transactions has_many :transactions
has_many :comments
end end
...@@ -5,7 +5,8 @@ class User < ApplicationRecord ...@@ -5,7 +5,8 @@ class User < ApplicationRecord
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
has_many :transactions has_many :transactions
# has_many :comments has_many :comments
def to_s def to_s
if first_name && last_name if first_name && last_name
"#{first_name} #{last_name}" "#{first_name} #{last_name}"
......
<h1>Comments#new</h1> <h3>Add Review</h3>
<p>Find me in app/views/comments/new.html.erb</p>
Comment for: <%= @product.name %>
<%= simple_form_for([@product, @comment]) do |f| %>
<%= f.input :comment %>
<%= f.button :submit, "Add Review" %>
<% end %>
<h1>Orders#create</h1>
<p>Find me in app/views/orders/create.html.erb</p>
<h1>New Order</h1>
<%= simple_form_for @order do |f| %>
<%= f.input :name %>
<%= f.input :description, as: :text %>
<%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Order", class: "btn btn-primary" %>
<% end %>
\ No newline at end of file
...@@ -33,9 +33,6 @@ ...@@ -33,9 +33,6 @@
</td> </td>
<td> <td>
<%= time_ago_in_words(product.created_at) %> ago <%= time_ago_in_words(product.created_at) %> ago
</td>
<td>
<%= link_to "Add Comment", new_post_comment_path(post), class: "btn btn-info" %>
</td> </td>
<td> <td>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %> <%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
......
<h1>Supplies#create</h1>
<p>Find me in app/views/supplies/create.html.erb</p>
<h1>Transactions</h1> <h1>Supplies</h1>
<% if @products.empty? %> <div>
<%= link_to "Add New Supply", new_product_supply_path, class: "btn btn-primary" %>
</div>
<br>
<% if @supplies.empty? %>
<small> <small>
No products have been created. No supplies available.
</small> </small>
<% else%> <% else %>
<table class="table"> <table class="table">
<thead> <thead>
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th>Status</th> <th>Date Added</th>
<th>Time Created</th> <th>Quantity</th>
<th colspan="4"></th> <th colspan="4"></th>
</thead> </thead>
<tbody> <tbody>
<% @products.each do |product| %> <% @supplies.each do |supply| %>
<tr> <tr>
<td> <td>
<%= link_to product.name, product_path(product) %> <%= link_to supply.name, supply_path(supply) %>
</td>
<td>
<%= supply.description %>
</td> </td>
<td> <td>
<%= product.description %> <%= time_ago_in_words(supply.created_at) %> ago
</td> </td>
<td> <td>
<%= product.status %> <%= supply.quantity %>
</td> </td>
<td> <td>
<%= time_ago_in_words(product.created_at) %> ago <%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
</td> </td>
</tr> </tr>
<% end %> <% end %>
......
<h1>New Supply</h1>
<%= simple_form_for @supply do |f| %>
<%= f.input :name %>
<%= f.input :description, as: :text %>
<%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Supply", class: "btn btn-primary" %>
<%= link_to "Back", supplies_path, class: "btn btn-default" %>
<% end %>
<h1>Add Order</h1>
<%= simple_form_for @product do |f| %>
<%= f.input :product_id, as: :integer %>
<%= f.input :user_id, as: :integer %>
<%= f.input :quantity, as: :integer %>
<%= f.input :mode, as: :string, collection: [['Active', 'Active'], ['Inactive', 'Inactive']], value_method: :first, label_method: :second %>
<%= f.button :submit, "Add Order", class: "btn btn-primary" %>
<%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %>
\ No newline at end of file
<h1>Add Supply</h1>
<%= simple_form_for @product do |f| %>
<%= f.input :product_id, as: :integer %>
<%= f.input :user_id, as: :integer %>
<%= f.input :quantity, as: :integer %>
<%= f.input :mode, as: :string, collection: [['Active', 'Active'], ['Inactive', 'Inactive']], value_method: :first, label_method: :second %>
<%= f.button :submit, "Add Supply", class: "btn btn-primary" %>
<%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %>
\ No newline at end of file
Rails.application.routes.draw do Rails.application.routes.draw do
get 'orders/new'
get 'orders/create'
get 'supplies/index'
get 'supplies/new'
get 'supplies/create'
get 'comments/new' get 'comments/new'
devise_for :admin_users devise_for :admin_users
devise_scope :admin_user do devise_scope :admin_user do
...@@ -17,7 +22,7 @@ Rails.application.routes.draw do ...@@ -17,7 +22,7 @@ Rails.application.routes.draw do
resources :supplies, only: [:new, :create] resources :supplies, only: [:new, :create]
resources :comments, only: [:new, :create] resources :comments, only: [:new, :create]
end end
root to: 'transactions#index', as: :authenticated_user_root root to: 'supplies#index', as: :authenticated_user_root
end end
end end
......
...@@ -3,7 +3,7 @@ class CreateComments < ActiveRecord::Migration[5.2] ...@@ -3,7 +3,7 @@ class CreateComments < ActiveRecord::Migration[5.2]
create_table :comments do |t| create_table :comments do |t|
t.text :comment t.text :comment
t.references :user, foreign_key: true t.references :user, foreign_key: true
t.references :post, foreign_key: true t.references :product, foreign_key: true
t.timestamps t.timestamps
end end
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_07_16_132511) do ActiveRecord::Schema.define(version: 2018_07_16_152823) do
create_table "admin_users", force: :cascade do |t| create_table "admin_users", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
...@@ -32,10 +32,10 @@ ActiveRecord::Schema.define(version: 2018_07_16_132511) do ...@@ -32,10 +32,10 @@ ActiveRecord::Schema.define(version: 2018_07_16_132511) do
create_table "comments", force: :cascade do |t| create_table "comments", force: :cascade do |t|
t.text "comment" t.text "comment"
t.integer "user_id" t.integer "user_id"
t.integer "post_id" t.integer "product_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["post_id"], name: "index_comments_on_post_id" t.index ["product_id"], name: "index_comments_on_product_id"
t.index ["user_id"], name: "index_comments_on_user_id" t.index ["user_id"], name: "index_comments_on_user_id"
end end
......
...@@ -2,12 +2,11 @@ if AdminUser.count == 0 ...@@ -2,12 +2,11 @@ if AdminUser.count == 0
AdminUser.create!( AdminUser.create!(
{ {
email: 'andrea.dolendo@obf.ateneo.edu', email: 'andrea.dolendo@obf.ateneo.edu',
password: 'Andrea25', password: 'Andrea25'
password_confirmation:'Andrea25'
}, },
{ # {
email: 'chanelle.lunod@obf.ateneo.edu', # email: 'chanelle.lunod@obf.ateneo.edu',
password: 'December5', # password: 'December5'
password_confirmation:'December5' # }
}) )
end end
\ No newline at end of file
require 'test_helper'
class OrdersControllerTest < ActionDispatch::IntegrationTest
test "should get new" do
get orders_new_url
assert_response :success
end
test "should get create" do
get orders_create_url
assert_response :success
end
end
require 'test_helper'
class SuppliesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get supplies_index_url
assert_response :success
end
test "should get new" do
get supplies_new_url
assert_response :success
end
test "should get create" do
get supplies_create_url
assert_response :success
end
end
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
one: one:
comment: MyText comment: MyText
user: one user: one
post: one product: one
two: two:
comment: MyText comment: MyText
user: two user: two
post: two product: two
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment