Commit 864ef5bf authored by Chanelle Lunod's avatar Chanelle Lunod

Initial commit

parent e67ef1de
......@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
def after_sign_in_path_for(resource)
if resource.is_a?(AdminUser)
authenticated_admin_user_root_url
elsif resource.is_a?(User)
else resource.is_a?(User)
authenticated_user_root_url
end
#authenticated_root_url
......@@ -14,12 +14,6 @@ class ApplicationController < ActionController::Base
end
def after_sign_out_path_for(resource)
if resource == :user
new_user_session_path
elsif resource == :admin_user
new_admin_user_session_path
else
root_path
end
end
end
\ No newline at end of file
......@@ -3,8 +3,6 @@ class ProductsController < ApplicationController
def index
@products = Product.all
#if @product.status == active
#else
end
def show
......@@ -39,6 +37,10 @@ class ProductsController < ApplicationController
end
end
def count
@products.count
end
private
def product_params
params.require(:product).permit!
......
......@@ -6,10 +6,7 @@ class TransactionsController < ApplicationController
end
def display
if @product.status == active
Products.find_by(id: [pramas[:id])
else
#dont display
@product = Product.find_by(id: params[:id])
end
def new
......
class Transaction < ApplicationRecord
belongs_to :product
belongs_to :user
end
......@@ -4,14 +4,14 @@ class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# has_many :transactions
# has_many :comments
# def to_s
# if first_name && last_name
# "#{first_name} #{last_name}"
# else
# email
# end
# end
has_many :transactions
# has_many :comments
def to_s
if first_name && last_name
"#{first_name} #{last_name}"
else
email
end
end
end
......@@ -5,7 +5,6 @@
<%= simple_form_for :admin_user, url: session_path(:admin_user) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.button :submit, "Log In" %>
<% end %>
</div>
......@@ -15,7 +14,6 @@
<%= simple_form_for :user, url: session_path(:user) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.button :submit, "Log In" %>
<%= link_to "Sign Up", new_user_registration_path, :class => 'navbar-link' %>
<% end %>
......
<h1>Transactions</h1>
<% if @products.empty? %>
<small>
No products have been created.
</small>
<% elsif @products.status == active %>
<% else%>
<table class="table">
<thead>
<th>Name</th>
......@@ -29,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>
......
......@@ -5,9 +5,7 @@ Rails.application.routes.draw do
resources :products
root to: 'products#index', as: :authenticated_admin_user_root
end
unauthenticated :admin_user do
root to: 'publics#index', as: :unauthenticated_admin_user_root
end
end
devise_for :users
......@@ -19,9 +17,7 @@ Rails.application.routes.draw do
end
root to: 'transactions#index', as: :authenticated_user_root
end
unauthenticated :user do
root to: 'publics#index', as: :unauthenticated_user_root
end
end
root to: 'publics#index'
end
class CreateTransactions < ActiveRecord::Migration[5.2]
def change
create_table :transactions do |t|
t.integer :product_id
t.integer :user_id
t.integer :quantity
t.string :mode
t.timestamps
end
end
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_12_181949) do
ActiveRecord::Schema.define(version: 2018_07_15_111200) do
create_table "admin_users", force: :cascade do |t|
t.string "email", default: "", null: false
......@@ -37,6 +37,15 @@ ActiveRecord::Schema.define(version: 2018_07_12_181949) do
t.datetime "updated_at", null: false
end
create_table "transactions", force: :cascade do |t|
t.integer "product_id"
t.integer "user_id"
t.integer "quantity"
t.string "mode"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
......
if AdminUser.count == 0
AdminUser.create!
({
AdminUser.create!(
{
email: 'andrea.dolendo@obf.ateneo.edu',
password: 'Andrea25',
password_confirmation:'Andrea25'
},
{
email: 'chanelle.lunod@obf.ateneo.edu',
password: 'December5',
password_confirmation:'December5'
})
end
\ No newline at end of file
if AdminUser.valid?
admin.save()
# email: 'chanelle.lunod@obf.ateneo.edu',
# password: 'December5',
# password_confirmation:'December5'
\ No newline at end of file
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
product_id: 1
user_id: 1
quantity: 1
mode: MyString
two:
product_id: 1
user_id: 1
quantity: 1
mode: MyString
require 'test_helper'
class TransactionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
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