Skip to content

Commit

Permalink
All routes and controllers debugged and working
Browse files Browse the repository at this point in the history
  • Loading branch information
kenney-g committed Sep 15, 2020
1 parent 5f09dff commit f71f8c5
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 43 deletions.
8 changes: 4 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class ApplicationController < Sinatra::Base
erb :'welcome'
end

not_found do
flash[:error] = "Whoops! Couldn't find that route"
redirect "/"
end
# not_found do
# flash[:error] = "I got lost, sorry. 404. Error beep boop bop."
# redirect "/"
# end

private
def current_user
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ class LogsController < ApplicationController
end
end

# DELETE: /logs/5/delete
delete "/logs/:id/" do
#DELETE: /logs/5/delete
delete '/logs/:id' do
set_log
redirect_if_not_authorized
@log.destroy
redirect "/logs"
@log.id = Log.delete(params[:id])
redirect to("/users")
end

private
Expand All @@ -64,12 +63,13 @@ def set_log
@log = Log.find_by_id(params[:id])
if @log.nil?
flash[:error] = "Couldn't find a log with id: #{params[:id]}"
redirect "/logs/"
redirect "/logs"
end
end


def redirect_if_not_authorized
redirect_if_not_logged_in
if !authorize_log(@log)
flash[:error] = "You don't have permission to do that action"
redirect "/logs"
Expand Down
6 changes: 2 additions & 4 deletions app/views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@
</div> -->
<br>
<div>
<a href="#top" class="back-to-top">
<img src="http://u.cubeupload.com/kkslidermight/arrow.png" alt="Back to Top" width="35" height="25" class="back-to-top">
</a>

<!-- footer -->
<hr class="my-4">
<p class="text-muted">This website was designed for Flatiron School's software development course.</p>
</div>
<footer"10px">
<footer>
<div id="accordion">
<div class="card">
<div class="card-header" id="headingOne">
Expand Down
43 changes: 17 additions & 26 deletions app/views/logs/show.erb
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
<br>
<table class="table table-striped table-hover ">
<thead>
<tr>
<th>Title</th>
<th>Console</th>
<th>Description</th>
<th>Author</th>
</tr>
</thead>
<tbody>
<tr>
<td><%= @log.game_title %> </td>
<td><%= @log.game_console%></td>
<td><%= @log.game_desc%></td>
<td><%= @log.author.username%></td>
</tr>
</tbody>
</table>

<br>
<div class="well well-sm">
<h1>Title: <%= @log.game_title %></h1>
</div>
<div class="well well-sm">
<p>Console: <%= @log.game_console %></p>
</div>
<div class="well well-sm">
<p>Description: <%= @log.game_desc %></p>
</div>
<div class="well well-sm">
<p>Logged by <%= @log.author.username %></p>
</div>
<% if authorize_log(@log) %>
<div>
<div class="well well-sm">
<a href="/logs/<%= @log.id %>/edit"><button>Edit</button></a>
<form method="post" action="/logs/<%= @log.id %>" style="display: inline-block;">
<input type="hidden" name="_method" value="delete" />
<input type="submit" value="Delete" />
</form>
<form action="/logs/<%=@log.id%>" method="post">
<input type="hidden" name="_method" value="DELETE">
<input type="submit" value="Delete">
</form>
</div>
<% end %>
3 changes: 2 additions & 1 deletion app/views/users/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
</div>
<%end%>


<button type="button" class="btn btn-link"><a href="/logs/new">Add a new entry</a></button>
<button type="button" class="btn btn-link"><a href="/logs">View all</a></button>
Binary file modified db/development.sqlite
Binary file not shown.
Empty file removed instructionds.md
Empty file.
2 changes: 1 addition & 1 deletion public/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ body {
}

.well {
margin-left: 10px;
margin-left: 50px;
max-width: 25%;
}
2 changes: 1 addition & 1 deletion spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Specs:
- [x] Ensure that the belongs_to resource has routes for Creating, Reading, Updating and Destroying
- [x ] Ensure that users can't modify content created by other users
- [x] Include user input validations
- [ ] BONUS - not required - Display validation failures to user with error message (example form URL e.g. /posts/new)
- [x] BONUS - not required - Display validation failures to user with error message (example form URL e.g. /posts/new)
- [x] Your README.md includes a short description, install instructions, a contributors guide and a link to the license for your code

Confirm
Expand Down

0 comments on commit f71f8c5

Please sign in to comment.