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

Initial commit

parent e67ef1de
...@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base ...@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
def after_sign_in_path_for(resource) def after_sign_in_path_for(resource)
if resource.is_a?(AdminUser) if resource.is_a?(AdminUser)
authenticated_admin_user_root_url authenticated_admin_user_root_url
elsif resource.is_a?(User) else resource.is_a?(User)
authenticated_user_root_url authenticated_user_root_url
end end
#authenticated_root_url #authenticated_root_url
...@@ -14,12 +14,6 @@ class ApplicationController < ActionController::Base ...@@ -14,12 +14,6 @@ class ApplicationController < ActionController::Base
end end
def after_sign_out_path_for(resource) 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 root_path
end end
end
end end
\ No newline at end of file
...@@ -3,8 +3,6 @@ class ProductsController < ApplicationController ...@@ -3,8 +3,6 @@ class ProductsController < ApplicationController
def index def index
@products = Product.all @products = Product.all
#if @product.status == active
#else
end end
def show def show
...@@ -39,6 +37,10 @@ class ProductsController < ApplicationController ...@@ -39,6 +37,10 @@ class ProductsController < ApplicationController
end end
end end
def count
@products.count
end
private private
def product_params def product_params
params.require(:product).permit! params.require(:product).permit!
......
...@@ -6,10 +6,7 @@ class TransactionsController < ApplicationController ...@@ -6,10 +6,7 @@ class TransactionsController < ApplicationController
end end
def display def display
if @product.status == active @product = Product.find_by(id: params[:id])
Products.find_by(id: [pramas[:id])
else
#dont display
end end
def new def new
......
class Transaction < ApplicationRecord
belongs_to :product
belongs_to :user
end
...@@ -4,14 +4,14 @@ class User < ApplicationRecord ...@@ -4,14 +4,14 @@ class User < ApplicationRecord
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
: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}"
# else else
# email email
# end end
# end end
end end
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
<%= simple_form_for :admin_user, url: session_path(:admin_user) do |f| %> <%= simple_form_for :admin_user, url: session_path(:admin_user) do |f| %>
<%= f.input :email %> <%= f.input :email %>
<%= f.input :password %> <%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.button :submit, "Log In" %> <%= f.button :submit, "Log In" %>
<% end %> <% end %>
</div> </div>
...@@ -15,7 +14,6 @@ ...@@ -15,7 +14,6 @@
<%= simple_form_for :user, url: session_path(:user) do |f| %> <%= simple_form_for :user, url: session_path(:user) do |f| %>
<%= f.input :email %> <%= f.input :email %>
<%= f.input :password %> <%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.button :submit, "Log In" %> <%= f.button :submit, "Log In" %>
<%= link_to "Sign Up", new_user_registration_path, :class => 'navbar-link' %> <%= link_to "Sign Up", new_user_registration_path, :class => 'navbar-link' %>
<% end %> <% end %>
......
<h1>Transactions</h1> <h1>Transactions</h1>
<% if @products.empty? %> <% if @products.empty? %>
<small> <small>
No products have been created. No products have been created.
</small> </small>
<% elsif @products.status == active %> <% else%>
<table class="table"> <table class="table">
<thead> <thead>
<th>Name</th> <th>Name</th>
...@@ -29,12 +28,6 @@ ...@@ -29,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>
......
...@@ -5,9 +5,7 @@ Rails.application.routes.draw do ...@@ -5,9 +5,7 @@ Rails.application.routes.draw do
resources :products resources :products
root to: 'products#index', as: :authenticated_admin_user_root root to: 'products#index', as: :authenticated_admin_user_root
end end
unauthenticated :admin_user do
root to: 'publics#index', as: :unauthenticated_admin_user_root
end
end end
devise_for :users devise_for :users
...@@ -19,9 +17,7 @@ Rails.application.routes.draw do ...@@ -19,9 +17,7 @@ Rails.application.routes.draw do
end end
root to: 'transactions#index', as: :authenticated_user_root root to: 'transactions#index', as: :authenticated_user_root
end end
unauthenticated :user do
root to: 'publics#index', as: :unauthenticated_user_root
end
end end
root to: 'publics#index' root to: 'publics#index'
end 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 @@ ...@@ -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_12_181949) do ActiveRecord::Schema.define(version: 2018_07_15_111200) 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
...@@ -37,6 +37,15 @@ ActiveRecord::Schema.define(version: 2018_07_12_181949) do ...@@ -37,6 +37,15 @@ ActiveRecord::Schema.define(version: 2018_07_12_181949) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end 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| create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
......
if AdminUser.count == 0 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' password_confirmation:'Andrea25'
},
{
email: 'chanelle.lunod@obf.ateneo.edu',
password: 'December5',
password_confirmation:'December5'
}) })
end 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