diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 06a8041b..0722fe94 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -21,6 +21,7 @@ def index # GET /courses/1.json def show @reviews = @course.reviews.preload(:user, course: [:school]) + @url = school_course_reviews_path(school_id: @school, course_id: @course) end # GET /courses/new diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 7f48851c..cab06940 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -12,7 +12,7 @@ class ReviewsController < ApplicationController def index if params[:course_id].to_i.zero? if params[:school_id].to_i.zero? - @reviews = Review.all + @reviews = Review.preload(:user, course: [:school]).all else set_school @reviews = Review.preload(:user, course: [:school]).joins(:course).where('courses.school_id = (?)', @school.id) @@ -42,6 +42,7 @@ def edit # POST /schools/1/courses/1/reviews # POST /schools/1/courses/1/reviews.json def create + @url = school_course_reviews_path @review = Review.new(review_params) respond_to do |format| if @review.save @@ -83,7 +84,11 @@ def update def destroy @review.destroy respond_to do |format| - format.html { redirect_to school_course_reviews_url, notice: 'Review was successfully destroyed.' } + format.html do + redirect_to school_course_reviews_url(school_id: @school, + course_id: @course), + notice: 'Review was successfully destroyed.' + end format.json { head :no_content } end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0dbf9b8a..3e7257e2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -59,7 +59,7 @@ def destroy # PUT /users/1/promote def promote @user.update(is_admin: true) - redirect_to users_url, notice: "#{@user.email} was successfully demoted from admin." + redirect_to users_url, notice: "#{@user.email} was successfully promoted to admin." end # PUT /users/1/demote diff --git a/app/models/ability.rb b/app/models/ability.rb index 4e15fb81..5b11a2ee 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -15,7 +15,7 @@ def initialize(user) can [:update, :delete], Review do |r| r.user == user end - can [:update, :delete], User do |u| + can [:read, :update, :delete], User do |u| u == user end return unless user.admin? diff --git a/app/views/courses/edit.html.erb b/app/views/courses/edit.html.erb index 2d2f4231..fbd7d050 100644 --- a/app/views/courses/edit.html.erb +++ b/app/views/courses/edit.html.erb @@ -2,4 +2,4 @@ <%= render 'form', course: @course %> -<%= link_to 'Show', school_course_path(school_id: @school.id, id: @course.id) %> | +<%= link_to 'Show', school_course_path(school_id: @school.id, id: @course.id) %> diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb index eb4d5920..3b0fecf1 100644 --- a/app/views/courses/index.html.erb +++ b/app/views/courses/index.html.erb @@ -1,5 +1,3 @@ -

<%= notice %>

-

Courses

<% if can? :create, Course %> <% if @school %> @@ -8,30 +6,34 @@ <%= link_to 'Select a school first to add a new course', schools_path %> <% end %> <% end %> - - - - - - - - - - - - - - <% @courses.each do |course| %> +
+<% if @courses.load.empty? %> + No courses at this time! +<% else %> +
NameNumberDepartmentSchool
+ - - - - - - <% end %> + + + + + - <% end %> - -
<%= link_to course.name, school_course_path(id: course.id, school_id: course.school.id) %><%= course.number %><%= course.department %><%= link_to course.school.name, school_path(id: course.school) %> - <% if can? :edit, course %> - <%= link_to 'Edit', edit_school_course_path(id: course.id, school_id: course.school.id) %><%= link_to 'Destroy', school_course_path(id: course.id, school_id: course.school.id), method: :delete, data: { confirm: 'Are you sure?' } %>NameNumberDepartmentSchool
+ + + + <% @courses.each do |course| %> + + <%= link_to course.name, school_course_path(id: course.id, school_id: course.school.id) %> + <%= course.number %> + <%= course.department %> + <%= link_to course.school.name, school_path(id: course.school) %> + <% if can? :edit, course %> + <%= link_to 'Edit', edit_school_course_path(id: course.id, school_id: course.school.id) %> + <%= link_to 'Destroy', school_course_path(id: course.id, school_id: course.school.id), method: :delete, data: { confirm: 'Are you sure?' } %> + <% end %> + + <% end %> + + +<% end %> \ No newline at end of file diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index e9952861..133808f9 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -1,7 +1,7 @@

<%= @course.name %> at <%= link_to @course.school.name, @course.school %>

<% if can? :edit, @course %> -<%= link_to 'Edit', edit_school_course_path(@course) %> +<%= link_to 'Edit', edit_school_course_path(school_id: @school.id, course_id: @course.id) %> <% end %>

Number: @@ -15,6 +15,9 @@

Reviews

- <%= link_to 'New Review', new_school_course_review_path(school_id: @school.id, course_id: @course.id) %> + <% if can? :create, Review %> + <%= link_to 'New Review', new_school_course_review_path(school_id: @school.id, course_id: @course.id) %> + <% end %> +
<%= render 'reviews/review_index', reviews: @reviews %>

diff --git a/app/views/reviews/_review_index.html.erb b/app/views/reviews/_review_index.html.erb index 6bdc9658..c876dc92 100644 --- a/app/views/reviews/_review_index.html.erb +++ b/app/views/reviews/_review_index.html.erb @@ -1,4 +1,4 @@ -<% if reviews.empty? %> +<% if reviews.load.empty? %> No reviews at this time! <% else %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index b3977005..1178ae26 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,7 +1,6 @@ -

<%= notice %>

- -

Users

- +<% if can? :manage, User %> +

Users

@@ -29,7 +28,4 @@ <% end %>
- -
- -<%= link_to 'New User', new_user_path %> +<% end %> \ No newline at end of file diff --git a/coverage/.resultset.json b/coverage/.resultset.json index ff00e34d..5598cac1 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -120,6 +120,7 @@ null, 1, 2, + 2, null, null, null, @@ -251,6 +252,7 @@ 5, 5, 5, + 5, 2, 2, null, @@ -413,7 +415,7 @@ null, null, 1, - 4, + 5, null, null, null, @@ -664,6 +666,6 @@ null ] }, - "timestamp": 1559940230 + "timestamp": 1560033163 } } diff --git a/coverage/index.html b/coverage/index.html index ed1339f9..023460f5 100644 --- a/coverage/index.html +++ b/coverage/index.html @@ -14,7 +14,7 @@ loading