Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end


gem 'devise', '4.3.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.6'
# Use sqlite3 as the database for Active Record
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ GEM
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
arel (8.0.0)
bcrypt (3.1.11)
bindex (0.5.0)
builder (3.2.3)
byebug (10.0.2)
Expand All @@ -62,6 +63,12 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
crass (1.0.3)
devise (4.3.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.2)
responders
warden (~> 1.2.3)
erubi (1.7.1)
execjs (2.7.0)
ffi (1.9.23)
Expand Down Expand Up @@ -89,6 +96,7 @@ GEM
nio4r (2.3.0)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
public_suffix (3.0.2)
puma (3.11.3)
rack (2.0.4)
Expand Down Expand Up @@ -121,6 +129,9 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
ruby_dep (1.5.0)
rubyzip (1.2.1)
sass (3.5.6)
Expand Down Expand Up @@ -160,6 +171,8 @@ GEM
thread_safe (~> 0.1)
uglifier (4.1.8)
execjs (>= 0.3.0, < 3)
warden (1.2.7)
rack (>= 1.0)
web-console (3.5.1)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand All @@ -178,6 +191,7 @@ DEPENDENCIES
byebug
capybara (~> 2.13)
coffee-rails (~> 4.2)
devise (= 4.3.0)
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
puma (~> 3.7)
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/cart_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class CartController < ApplicationController

before_action :authenticate_user!
def add
# get id of the product
id = params[:id]
Expand Down Expand Up @@ -51,7 +51,10 @@ def remove
redirect_to :action => :index
end


def clearCart
session[:cart] = nil
redirect_to :action => :index
end



Expand Down
1 change: 1 addition & 0 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def login
session[:login] = 1
flash[:notice] = "you are logged in"
redirect_to :controller => :items
#session[:cart] = nil
end
def logout
#in case things go crazy and impossible to understand uncomment the line below and logout /login
Expand Down
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
12 changes: 11 additions & 1 deletion app/views/cart/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<p id="notice"><%= notice %></p>

<div id="itemsContainer">

<% if@cart.empty? %>
<p>Your cart is empty, please add somthing to make a purchase</p>
<% end %>

<table id="customers">
<% total = 0 %>
<% @cart.each do |id, quantity| %>
Expand Down Expand Up @@ -35,10 +40,15 @@
<td>
Grand Total: <%= number_to_currency(total, :unit => "€") %>
</td>

</tr>


</table>


<p>
<a href="/items" class="button">Continue Shopping</a>
<a href="/cart/clear" class="button"> Clear Cart</a>

</p>
</div>
12 changes: 9 additions & 3 deletions app/views/items/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<%= link_to (image_tag item.image_url, :class => "itemImage"), item %>

<p>
<%= item.console %>
Console: <%= item.console %>
<br>
<%= item.brand %>
Brand: <%= item.brand %>
<br>
<%= item.genre %>
Genre: <%= item.genre %>
</p>

<p><%= item.description %></p>
Expand All @@ -24,8 +24,14 @@
<p>
<a href = "/cart/<%= item.id %>" class = "button">Add to cart</a>
<%= link_to 'Show', item, :class => "button", :role => "button" %>

<% if user_signed_in? %>
<%= link_to 'Edit', edit_item_path(item), :class => "button", :role => "button" %>
<%= link_to 'Destroy', item, method: :delete, data: { confirm: 'Are you sure?' }, :class => "button", :role => "button" %></td>
<% end %>



</p>
</div>
<% end %>
Expand Down
2 changes: 0 additions & 2 deletions app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<% if session[:login] == 1 %>
<%= link_to 'New Item', new_item_path,:class =>"button", :role=>"button" %>



<% end %>

</footer>
11 changes: 7 additions & 4 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
<li><%= link_to "About", about_path %></li>
<li><%= link_to "Help", help_path %></li>
<li><%= link_to "Cart", cart_path %></li>
<% if session[:login] == 1 %>
<li><%= link_to "Logout", logout_path %></li>
<% else %>

<li><%= link_to "Login", login_path %></li>
<% if user_signed_in? %>
<li><a href="#">Hi <%= current_user.email %></a></li>
<li><%= link_to 'Sign Out', destroy_user_session_path, :method =>:delete %></li>
<% else %>
<li><%= link_to 'Register', new_user_registration_path %></li>
<li><%= link_to 'Sign In', new_user_session_path %></li>
<% end %>



</ul>
Expand Down
Loading