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

initial commit

parents dc2de209 cafc98c4
class CommentsController < ApplicationController 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 end
class OrdersController < ApplicationController class OrdersController < ApplicationController
def new def new
@order = Order.new @orders = Order.new
end end
def create 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" redirect_to products_path, notice: "You have successfully placed a new order"
else else
render 'new' render 'new'
...@@ -15,11 +15,11 @@ class OrdersController < ApplicationController ...@@ -15,11 +15,11 @@ class OrdersController < ApplicationController
end end
def show def show
if params [:status] == "activated" if params [:status] == 'Active'
@products = Product.activated @products = Product.Active
else else
@products = Product.inactivated @products = Product.Inactive
end end
end end
end end
class SuppliesController < ApplicationController class SuppliesController < ApplicationController
def index def index
if params [:status] == "activated" @products = Product.all
@products = Product.activated
else
@products = Product.inactivated
end
end end
def new def new
@supply = Supply.new @supplies = Supply.new
end end
def create 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." redirect_to products_path, notice: "You have successfully added a new supply."
else else
render 'new' render 'new'
end end
end end
def show
if params [:status] == 'Active'
@products = Product.Active
else
@products = Product.Inactive
end
end
end 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
<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>Create Order</h1> <h1>Create Orders</h1>
...@@ -34,9 +34,6 @@ ...@@ -34,9 +34,6 @@
<td> <td>
<%= time_ago_in_words(product.created_at) %> ago <%= time_ago_in_words(product.created_at) %> ago
</td> </td>
<td>
<%= link_to "Add Comment", new_post_comment_path(post), class: "btn btn-info" %>
</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" %>
</td> </td>
......
<h1>Create Supply</h1> <h1>Create Supply</h1>
<h1>Supplies</h1> <h1>Supplies</h1>
<div> <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> </div>
<br> <br>
......
<h1>New Supply</h1> <h1>New Supply</h1>
<%= simple_form_for @supply do |f| %> <%= simple_form_for @supply do |f| %>
<%= f.input :name %> <%= f.input :name %>
<%= f.input :description, as: :text %> <%= f.input :description, as: :text %>
<%= f.input :quantity, as: :integer %> <%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Supply", class: "btn btn-primary" %> <%= f.button :submit, "Add Supply", class: "btn btn-primary" %>
<%= link_to "Back", supplies_path, class: "btn btn-default" %> <%= link_to "Back", supplies_path, class: "btn btn-default" %>
<% end %> <% end %>
...@@ -28,12 +28,6 @@ ...@@ -28,12 +28,6 @@
<td> <td>
<%= time_ago_in_words(product.created_at) %> ago <%= time_ago_in_words(product.created_at) %> ago
</td> </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> </tr>
<% end %> <% end %>
</tbody> </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] ...@@ -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
......
if AdminUser.count == 0 if AdminUser.count == 0
AdminUser.add
AdminUser.create!
( (
{
email: 'andrea.dolendo@obf.ateneo.edu',
password: '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
...@@ -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