Skip to content

Commit

Permalink
finish core mechanics and links
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdbass committed Sep 24, 2015
1 parent e9acb9b commit 0ed8c13
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 21 deletions.
27 changes: 22 additions & 5 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ class UsersController < ApplicationController
# GET /users
# GET /users.json
def index
@users = User.all
if logged_in?
if current_user.admin
@users = User.all
else
redirect_to home_path
end
else
redirect_to home_path
end
end

# GET /users/1
Expand Down Expand Up @@ -52,11 +60,20 @@ def update
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user.destroy
respond_to do |format|
format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
format.json { head :no_content }
if logged_in?
if current_user.admin
@user.destroy
respond_to do |format|
format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
format.json { head :no_content }
end
else
redirect_to home_path
end
else
redirect_to home_path
end

end

private
Expand Down
27 changes: 18 additions & 9 deletions app/views/people/approve_comments.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<% @comments.each do |comment| %>
<p>
<%= comment.name %></br>
<%= comment.body %></br>
<%= comment.approved %></br>
<%= button_to "Destroy", person_comment_path(comment.person_id, comment.id), method: :delete, data: { confirm: 'Are you sure?' } %>
<%= button_to "Approve", person_comment_approve_path(comment.person_id, comment.id), method: :put %>
</p>
<% end %>
<% if current_user.person_id == @person.id %>
<% if @comments.count != 0 %>
<% @comments.each do |comment| %>
<p>
<%= comment.name %></br>
<%= comment.body %></br>
<%= comment.approved %></br>
<%= button_to "Destroy", person_comment_path(comment.person_id, comment.id), method: :delete, data: { confirm: 'Are you sure?' } %>
<%= button_to "Approve", person_comment_approve_path(comment.person_id, comment.id), method: :put %>
</p>
<% end %>
<% else %>
<p> No new comments.</br>
<%= link_to "Back", 'javascript:history.go(-1);' %>
</p>

<% end %>
<%end%>
10 changes: 7 additions & 3 deletions app/views/people/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
<%= @person.bio %></br>
<%= @person.link%></br>
<%= image_tag @person.image.url(:thumb) %>
<%= link_to 'Edit Profile', edit_person_path(@person) %>
<%= link_to 'Destroy', @person, method: :delete, data: { confirm: 'Are you sure?' } %>
<%= link_to 'Back', home_path %>
<% if !current_user.nil? && current_user.person_id == @person.id %>
<%= link_to 'Edit Profile', edit_person_path(@person) %>
<%= link_to 'Destroy', @person, method: :delete, data: { confirm: 'Are you sure?' } %>
<%= link_to "Approve Comments", approve_the_comments_path(@person) %>
<% end %>

<%= link_to 'Back', 'javascript:history.go(-1);' %>
</p>
<% @comments.each do |comment| %>
<p>
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Rails.application.routes.draw do
root :to => 'users#index'
root :to => 'static_pages#home'
resources :user_sessions
resources :users

get 'login' => 'user_sessions#new', :as => :login
post 'logout' => 'user_sessions#destroy', :as => :logout
get '/people/:person_id/approve_comments' => 'people#approve_comments'
get '/people/:person_id/approve_comments' => 'people#approve_comments', :as => 'approve_the_comments'

get 'home' => 'static_pages#home'

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20150924005047_add_admin_column_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAdminColumnToUsers < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean, :default =>false
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150924000916) do
ActiveRecord::Schema.define(version: 20150924005047) do

create_table "comments", force: :cascade do |t|
t.string "name"
Expand All @@ -36,13 +36,14 @@
end

create_table "users", force: :cascade do |t|
t.string "email", null: false
t.string "email", null: false
t.string "crypted_password"
t.string "salt"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "person_id"
t.integer "sessions", default: 0
t.boolean "admin", default: false
end

add_index "users", ["email"], name: "index_users_on_email", unique: true
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0ed8c13

Please sign in to comment.