Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FarMarRails #21

Open
wants to merge 48 commits into
base: arhcas/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
fa56b21
Add code to try to seed the database. Not working yet.
lacuchilla Nov 18, 2015
51e841a
Seeded database with markets
CShekta Nov 18, 2015
ba5a9bd
Reassign array indexes to proper elements and seed data is now displa…
lacuchilla Nov 18, 2015
ff1f78a
Added edit and new views, routes, and methods for market
CShekta Nov 18, 2015
a40c15d
Add delete function for Market class and create model and controller …
lacuchilla Nov 18, 2015
7bcea25
Added Vendor views, controller, and routes for index, show, and new
CShekta Nov 18, 2015
02592f8
deleted market line in show vendor file
CShekta Nov 18, 2015
e75f30c
Add edit feature to vendor class
lacuchilla Nov 18, 2015
c46b23d
Add links to navigate between the edit, view, and show pages for vend…
lacuchilla Nov 18, 2015
f4a7a6a
Added model, controller, and seed data for Product and Sales
CShekta Nov 18, 2015
9fb719a
Added vendor market name method to show page
CShekta Nov 18, 2015
612b04f
Added sales and product nesting and associations. Added product new form
CShekta Nov 19, 2015
bf2b56f
Add has many products relationship to vendor class
lacuchilla Nov 19, 2015
6902d12
Fixed new form by creating specific create action and updating route …
CShekta Nov 19, 2015
9387916
change redirect path
CShekta Nov 19, 2015
c378e63
Working on edit function for products. this feature is not working yet.
lacuchilla Nov 19, 2015
ec31fa8
Working product edit
CShekta Nov 19, 2015
2fd3983
Created new form for sale
CShekta Nov 19, 2015
d64be08
Add ability to show the list of sales on the vendor page
lacuchilla Nov 19, 2015
b1074bf
Add ability for a vendor to see the total amount of their sales on th…
lacuchilla Nov 19, 2015
f2206d1
Added bootstrap container class, background, and divs to every page
CShekta Nov 19, 2015
ea1b45d
Working on fixing links in view pages to navigate correctly
lacuchilla Nov 20, 2015
0bdf861
Fixed link in new product page
CShekta Nov 20, 2015
486173d
Made the markets/ page to a table w/ style
CShekta Nov 20, 2015
755b71d
added more styling for markets
CShekta Nov 20, 2015
7a08131
Refactored vendor classes with tables, number_to_currency, and some m…
CShekta Nov 20, 2015
0f35a8d
refactored vendor show page more to include table-division class, and…
CShekta Nov 20, 2015
fcfae6f
Updated vendor index to access market data
CShekta Nov 20, 2015
92b8496
Added sales method and table for current month in vendor show page
CShekta Nov 20, 2015
3e12f6c
Changed routes to have sales#index vendor_sales_path and removed the …
CShekta Nov 20, 2015
5c60a8b
Add functionality to view all products for a particular vendor.
lacuchilla Nov 20, 2015
48aea68
Add dropdown to select products for a sale. Doesn't work yet.
lacuchilla Nov 20, 2015
6c6f1aa
Added user_type functionality to homepage to start to separate views …
CShekta Nov 20, 2015
c55834f
Refactored market show page to divide in if statement for user_type i…
CShekta Nov 20, 2015
d958bed
Added is_market add a market link to home page
CShekta Nov 20, 2015
51d662d
Added route to see all vendors if you are a vendor and link back to a…
CShekta Nov 20, 2015
71fa8f8
Separted user_type logic for vendor show page
CShekta Nov 20, 2015
0402cfa
separated user_type tables for sales data. not working yet
CShekta Nov 20, 2015
436ab37
Merged amy fonts and styles
CShekta Nov 20, 2015
1d0badd
changed one font. onto heroku
CShekta Nov 20, 2015
4fbf78a
Added pg and sqlite3 gems
CShekta Nov 20, 2015
7bb40a8
fixed sqlite3 gem and added csv gem
CShekta Nov 20, 2015
898a18c
really did add those gems
CShekta Nov 21, 2015
1bf6e68
Upgrade spring gem and binstubs
CShekta Nov 21, 2015
a07e17f
changed background image url
CShekta Nov 22, 2015
4734cea
Updated a couple lines to debug user_session
CShekta Nov 23, 2015
5f2b0f0
update css on one line
CShekta Nov 23, 2015
56d4286
Added comma
CShekta Nov 23, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
Expand All @@ -23,6 +22,7 @@ gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'csv'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

Expand All @@ -42,7 +42,14 @@ end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
gem 'better_errors'
gem 'binding_of_caller'
gem 'sqlite3'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

group :production do
gem 'pg'
end
13 changes: 12 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,25 @@ GEM
autoprefixer-rails (6.1.0.1)
execjs
json
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.2.0.2)
sass (~> 3.2)
builder (3.2.2)
byebug (8.2.0)
coderay (1.1.0)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
csv (2.7.3)
debug_inspector (0.0.2)
erubis (2.7.0)
execjs (2.6.0)
Expand All @@ -77,6 +83,7 @@ GEM
multi_json (1.11.2)
nokogiri (1.6.6.3)
mini_portile (~> 0.6.0)
pg (0.18.4)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -116,7 +123,7 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
spring (1.4.3)
spring (1.4.4)
sprockets (3.4.0)
rack (> 1, < 3)
sprockets-rails (2.3.3)
Expand Down Expand Up @@ -145,11 +152,15 @@ PLATFORMS

DEPENDENCIES
autoprefixer-rails
better_errors
binding_of_caller
bootstrap-sass (~> 3.2.0)
byebug
coffee-rails (~> 4.1.0)
csv
jbuilder (~> 2.0)
jquery-rails
pg
rails (= 4.2.5)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
Expand Down
Binary file added app/assets/images/blue.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/border.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/cherry.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/foodpic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/strawberry.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/veggie.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/javascripts/products.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 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/
3 changes: 3 additions & 0 deletions app/assets/javascripts/sales.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 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/
3 changes: 3 additions & 0 deletions app/assets/javascripts/vendors.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 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/
15 changes: 0 additions & 15 deletions app/assets/stylesheets/application.css

This file was deleted.

76 changes: 76 additions & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
@import "bootstrap-sprockets";
@import "bootstrap";
@import url(https://fonts.googleapis.com/css?family=Montserrat);
@import url(https://fonts.googleapis.com/css?family=EB+Garamond);
@import url(https://fonts.googleapis.com/css?family=Fjalla+One);
@import url(https://fonts.googleapis.com/css?family=PT+Serif);
@import url(https://fonts.googleapis.com/css?family=Muli);


body {
font-family: 'PT Serif', serif;
font-size: 16px;
line-height: 23px;
margin: 0 0 23px 0;
margin: 0;
background: image-url('blue.jpg');
background-size: 1440px 800px;
display: compact;
}

div {
background-color: #F1F2F2;
opacity: 0.95;
padding: 30px;
margin: 60px;
}

.container {
margin-top: 50px;
margin-bottom: 20px;
padding-bottom: 20px;
}

h1 {
text-align: center;
padding: 25px;
padding-top: 40px;
font-family: 'Muli', sans-serif;
font-weight: normal;
text-transform: uppercase;
line-height: 50px;
font-size: 50px;
margin: 0 0 23px 0;
}

h2 {
text-align: center;
}

.table-division {
border-top-style: solid;
border-top-width: medium;
}

footer {
text-align: center;
}

.sales {
font-family: 'Muli', sans-serif;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/products.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Products controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sales.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Sales controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/vendors.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Vendors controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
50 changes: 48 additions & 2 deletions app/controllers/markets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
class MarketsController < ApplicationController

def home

end

def index
@is_market = true if session[:user_type] == "market"
user = params[:user_type]
session[:user_type] = user unless user.nil?
@markets = Market.all

end

def show
id = params[:id]
@market = Market.find(id)
@market = Market.find(params[:id])
@is_market = true if session[:user_type] == "market"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By using the one-line conditionals here with the ifs, your code will attempt execution on each individual conditional. The problem with this is that each conditional is actually mutually exclusive, so if the first one is true, it should not continue attempting to execute the rest of the conditionals.
I think that an if/elsif/else condition would be better suited here.

@is_vendor = true if session[:user_type] == "vendor"
@if_guest = true if session[:user_type] == "guest"
end

def new
@market = Market.new
end

def create
market = Market.create(market_params[:market])
redirect_to "/markets/#{market.id}"
end

def edit
@market = Market.find(params[:id])
name = params[:name]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to populate each of these individual local variables? What/where are they being used?

address = params[:address]
city = params[:city]
county = params[:county]
state = params[:state]
zip = params[:zip]
end

def update
@market = Market.find(params[:id])
Market.update(params[:id], market_params[:market])
redirect_to "/markets/#{@market.id}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a named route which corresponds to this that you can use instead of the URL itself?

end

def destroy
Market.destroy(params[:id])
redirect_to "/markets/"
end

private

def market_params
params.permit(market: [:name, :address, :city, :county, :state, :zip])
end

end
36 changes: 36 additions & 0 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class ProductsController < ApplicationController
def index
@products = Product.all
end

def new
@product = Product.new
end

def create
product = Product.create(name: product_params[:product][:name], vendor_id: params[:vendor_id])
redirect_to vendor_path(params[:vendor_id])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of the named route here

end

def edit
@product = Product.find(params[:id])
name = params[:name]
end

def update
@product = Product.find(params[:id])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this @product variable is never being used

Product.update(params[:id], product_params[:product])
redirect_to vendor_path(params[:vendor_id])
end

def destroy
Product.destroy(params[:id])
redirect_to vendor_path(params[:vendor_id])
end

private

def product_params
params.permit(product: [:name])
end
end
25 changes: 25 additions & 0 deletions app/controllers/sales_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class SalesController < ApplicationController

def index
@vendor = Vendor.find(params[:vendor_id])
@is_market = true if session[:user_type] == "market"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment re: the if/elsif/else conditional

@is_vendor = true if session[:user_type] == "vendor"
@if_guest = true if session[:user_type] == "guest"
end

def new
@sale = Sale.new
@vendor = Vendor.find(params[:vendor_id])
end

def create
@sale = Sale.create(amount: sales_params[:sale][:amount], purchase_time: sales_params[:sale][:purchase_time], product_id: params[:product_id], vendor_id: params[:vendor_id])
redirect_to vendor_path(params[:vendor_id])
end

private

def sales_params
params.permit(sale: [:amount, :purchase_time, :product_id, :vendor_id])
end
end
50 changes: 50 additions & 0 deletions app/controllers/vendors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class VendorsController < ApplicationController
def index
@vendors = Vendor.all
@is_market = true if session[:user_type] == "market"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment re: the if/elsif/else conditional (also in show method below)

@is_vendor = true if session[:user_type] == "vendor"
@if_guest = true if session[:user_type] == "guest"
end

def show
@vendor = Vendor.find(params[:id])
@market = Market.find(@vendor.market_id)
@is_market = true if session[:user_type] == "market"
@is_vendor = true if session[:user_type] == "vendor"
@if_guest = true if session[:user_type] == "guest"
end

def new
@vendor = Vendor.new
end

def create
vendor = Vendor.create(vendor_params[:vendor])
redirect_to "/vendors/#{vendor.id}"
end

def edit
@vendor = Vendor.find(params[:id])
name = params[:name]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these local variables being used?

employee_no = params[:employee_no]
market_id = params[:market_id]
end

def update
@vendor = Vendor.find(params[:id])
Vendor.update(params[:id], vendor_params[:vendor])
redirect_to "/vendors/#{@vendor.id}"
end

def destroy
Vendor.destroy(params[:id])
redirect_to "/vendors/"
end

private

def vendor_params
params.permit(vendor: [:name, :employee_no, :market_id])
end

end
2 changes: 2 additions & 0 deletions app/helpers/products_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ProductsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/sales_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SalesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/vendors_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module VendorsHelper
end
1 change: 1 addition & 0 deletions app/models/market.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class Market < ActiveRecord::Base
has_many :vendors
end
4 changes: 4 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Product < ActiveRecord::Base
has_many :sales
belongs_to :vendor
end
Loading