Commit 30167da0 authored by Chanelle Lunod's avatar Chanelle Lunod

initial commit

parents dc2de209 cafc98c4
class CommentsController < ApplicationController
def new
end
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
class OrdersController < ApplicationController
def new
@order = Order.new
@orders = Order.new
end
def create
@order = Order.new(product_params)
@orders = Order.new(product_params)
if @order.save
if @orders.save
redirect_to products_path, notice: "You have successfully placed a new order"
else
render 'new'
......@@ -15,11 +15,11 @@ class OrdersController < ApplicationController
end
def show
if params [:status] == "activated"
@products = Product.activated
if params [:status] == 'Active'
@products = Product.Active
else
@products = Product.inactivated
@products = Product.Inactive
end
end
end
end
class SuppliesController < ApplicationController
def index
if params [:status] == "activated"
@products = Product.activated
else
@products = Product.inactivated
end
@products = Product.all
end
def new
@supply = Supply.new
@supplies = Supply.new
end
def create
@supply = Supply.new(product_params)
@supplies = Supply.new(product_params)
if @supply.save
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
class Comment < ApplicationRecord
belongs_to :user
belongs_to :post
belongs_to :product
end
class Product < ApplicationRecord
has_many :transactions
has_many :comments
end
<h1>Comments#new</h1>
<p>Find me in app/views/comments/new.html.erb</p>
<h3>Add Review</h3>
Comment for: <%= @product.name %>
<%= simple_form_for([@product, @comment]) do |f| %>
<%= f.input :comment %>
<%= f.button :submit, "Add Review" %>
<% end %>
<h1>Create Order</h1>
<h1>Create Orders</h1>
......@@ -34,9 +34,6 @@
<td>
<%= 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>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
</td>
......
<h1>Supplies</h1>
<div>
<%= link_to "Add New Supply", new_supply_path, class: "btn btn-primary" %>
<%= link_to "Add New Supply", new_product_supply_path, class: "btn btn-primary" %>
</div>
<br>
......
<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" %>
<%= 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 %>
......@@ -28,12 +28,6 @@
<td>
<%= time_ago_in_words(product.created_at) %> ago
</td>
<!-- <td>
<%= link_to "Add Order", order_transaction_path(product), class: "btn btn-primary" %>
</td>
<td>
<%= link_to "Add Supply", supply_transaction_path(product), class: "btn btn-primary" %>
</td> -->
</tr>
<% end %>
</tbody>
......
<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
......@@ -3,7 +3,7 @@ class CreateComments < ActiveRecord::Migration[5.2]
create_table :comments do |t|
t.text :comment
t.references :user, foreign_key: true
t.references :post, foreign_key: true
t.references :product, foreign_key: true
t.timestamps
end
......
......@@ -10,7 +10,7 @@
#
# 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|
t.string "email", default: "", null: false
......@@ -32,10 +32,10 @@ ActiveRecord::Schema.define(version: 2018_07_16_132511) do
create_table "comments", force: :cascade do |t|
t.text "comment"
t.integer "user_id"
t.integer "post_id"
t.integer "product_id"
t.datetime "created_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"
end
......
if AdminUser.count == 0
AdminUser.create!
AdminUser.add
(
{
email: 'andrea.dolendo@obf.ateneo.edu',
password: 'Andrea25'
},
{
email: 'chanelle.lunod@obf.ateneo.edu',
password: 'December5',
password_confirmation:'December5'
password: 'December5'
}
)
end
\ No newline at end of file
......@@ -3,9 +3,9 @@
one:
comment: MyText
user: one
post: one
product: one
two:
comment: MyText
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