From 976747e3239a41a986964c78998b6857268942a4 Mon Sep 17 00:00:00 2001 From: Lamia Haider Date: Sun, 23 May 2021 11:41:44 -0400 Subject: [PATCH] Done. --- Gemfile.lock | 197 +++++++++++++++++++ app/controllers/classrooms_controller.rb | 2 +- app/controllers/students_controller.rb | 10 +- app/models/student.rb | 11 ++ app/views/classrooms/_classroom.html.erb | 2 + app/views/classrooms/show.html.erb | 11 +- app/views/students/_form.html.erb | 2 +- app/views/students/_student.html.erb | 6 +- app/views/students/edit.html.erb | 2 +- app/views/students/index.html.erb | 10 + app/views/students/new.html.erb | 2 +- app/views/students/show.html.erb | 3 +- db/schema.rb | 1 - spec/controllers/students_controller_spec.rb | 22 --- 14 files changed, 243 insertions(+), 38 deletions(-) create mode 100644 Gemfile.lock create mode 100644 app/views/classrooms/_classroom.html.erb create mode 100644 app/views/students/index.html.erb delete mode 100644 spec/controllers/students_controller_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..54fd7ea6d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,197 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.0.7.2) + actionpack (= 5.0.7.2) + nio4r (>= 1.2, < 3.0) + websocket-driver (~> 0.6.1) + actionmailer (5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.0.7.2) + actionview (= 5.0.7.2) + activesupport (= 5.0.7.2) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.0.7.2) + activesupport (= 5.0.7.2) + globalid (>= 0.3.6) + activemodel (5.0.7.2) + activesupport (= 5.0.7.2) + activerecord (5.0.7.2) + activemodel (= 5.0.7.2) + activesupport (= 5.0.7.2) + arel (~> 7.0) + activesupport (5.0.7.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + annotate (3.1.1) + activerecord (>= 3.2, < 7.0) + rake (>= 10.4, < 14.0) + arel (7.1.4) + bootsnap (1.7.5) + msgpack (~> 1.0) + builder (3.2.4) + coffee-rails (4.1.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.1.x) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.1.8) + crass (1.0.6) + diff-lcs (1.4.4) + erubis (2.7.0) + execjs (2.8.1) + faker (2.4.0) + i18n (~> 1.6.0) + ffi (1.15.1) + globalid (0.4.2) + activesupport (>= 4.2.0) + i18n (1.6.0) + concurrent-ruby (~> 1.0) + jbuilder (2.11.2) + activesupport (>= 5.0.0) + jquery-rails (4.4.0) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (1.8.6) + loofah (2.9.1) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + method_source (1.0.0) + mini_mime (1.1.0) + minitest (5.14.4) + msgpack (1.4.2) + nio4r (2.5.7) + nokogiri (1.11.5-x86_64-darwin) + racc (~> 1.4) + racc (1.5.2) + rack (2.2.3) + rack-test (0.6.3) + rack (>= 1.0) + rails (5.0.7.2) + actioncable (= 5.0.7.2) + actionmailer (= 5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) + activemodel (= 5.0.7.2) + activerecord (= 5.0.7.2) + activesupport (= 5.0.7.2) + bundler (>= 1.3.0) + railties (= 5.0.7.2) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (13.0.3) + rb-fsevent (0.11.0) + rb-inotify (0.10.1) + ffi (~> 1.0) + rdoc (4.3.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-rails (4.1.2) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.10.2) + sass (3.7.4) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + sdoc (0.4.2) + json (~> 1.7, >= 1.7.7) + rdoc (~> 4.0) + spring (2.1.1) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.2) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) + thor (1.1.0) + thread_safe (0.3.6) + tilt (2.0.10) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.9) + thread_safe (~> 0.1) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + +PLATFORMS + x86_64-darwin-19 + +DEPENDENCIES + annotate + bootsnap + coffee-rails (~> 4.1.0) + faker (~> 2.4.0) + jbuilder (~> 2.0) + jquery-rails + rails + rails-controller-testing + rspec-rails (>= 2.0.0.beta) + sass-rails (~> 5.0) + sdoc (~> 0.4.0) + spring + sqlite3 (~> 1.3.6) + turbolinks + uglifier (>= 1.3.0) + +BUNDLED WITH + 2.2.7 diff --git a/app/controllers/classrooms_controller.rb b/app/controllers/classrooms_controller.rb index 37b842336..a2f375b89 100644 --- a/app/controllers/classrooms_controller.rb +++ b/app/controllers/classrooms_controller.rb @@ -1,7 +1,7 @@ class ClassroomsController < ApplicationController def show @classroom = Classroom.find(params[:id]) - @student = @classroom.oldest_student + end def index diff --git a/app/controllers/students_controller.rb b/app/controllers/students_controller.rb index 4cfeaba94..8d49a2c50 100644 --- a/app/controllers/students_controller.rb +++ b/app/controllers/students_controller.rb @@ -1,4 +1,11 @@ class StudentsController < ApplicationController + + + def index + @students = Student.all + end + + def new @student = Student.new end @@ -20,9 +27,6 @@ def show @student = Student.find(params[:id]) end - def index - @students = Student.all - end def student_params params.require(:student).permit(:name, :birthday, :hometown) diff --git a/app/models/student.rb b/app/models/student.rb index 2e5955377..d64df60f4 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -13,4 +13,15 @@ class Student < ActiveRecord::Base has_many :classroom_students has_many :classrooms, through: :classroom_students + + + def self.search(name) + if name.present? + self.where('NAME like ?', "%#{name}%") + else + self.all + end + + + end end diff --git a/app/views/classrooms/_classroom.html.erb b/app/views/classrooms/_classroom.html.erb new file mode 100644 index 000000000..1ebfb59ab --- /dev/null +++ b/app/views/classrooms/_classroom.html.erb @@ -0,0 +1,2 @@ +<%= classroom.course_name %> +<%= classroom.semester %> \ No newline at end of file diff --git a/app/views/classrooms/show.html.erb b/app/views/classrooms/show.html.erb index e1563ef13..30b29d99a 100644 --- a/app/views/classrooms/show.html.erb +++ b/app/views/classrooms/show.html.erb @@ -1,5 +1,8 @@ Classroom Info -

-<%= @classroom.course_name %> -<%= @classroom.semester %> -

+
+<%= render partial: 'classroom', locals: {classroom: @classroom} %> +
+Students: +<% @classroom.students.each do |student| %> + <%= render partial: 'students/student', locals: {student: student} %> +<% end %> \ No newline at end of file diff --git a/app/views/students/_form.html.erb b/app/views/students/_form.html.erb index 89d2115e2..2e45abacf 100644 --- a/app/views/students/_form.html.erb +++ b/app/views/students/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for @student do |f|%> +<%= form_for student do |f|%>

<%= f.label :name %> <%= f.text_field :name %> diff --git a/app/views/students/_student.html.erb b/app/views/students/_student.html.erb index 2998c1197..2e0e23e15 100644 --- a/app/views/students/_student.html.erb +++ b/app/views/students/_student.html.erb @@ -1,11 +1,11 @@

diff --git a/app/views/students/edit.html.erb b/app/views/students/edit.html.erb index 2d3436368..6394145bb 100644 --- a/app/views/students/edit.html.erb +++ b/app/views/students/edit.html.erb @@ -1 +1 @@ -<%= render 'form' %> +<%= render partial: 'form', :locals => { student: @student } %> diff --git a/app/views/students/index.html.erb b/app/views/students/index.html.erb new file mode 100644 index 000000000..ab5abc883 --- /dev/null +++ b/app/views/students/index.html.erb @@ -0,0 +1,10 @@ +<%= form_tag students_path(@students), method: :get do %> +

+ <%= text_field_tag :name, params[:name] %> + <%= submit_tag "Search", name: nil %> +

+ +<% end %> +<% @students.each do |student| %> + <%= render partial: 'student', locals: {student: student} %> +<% end %> \ No newline at end of file diff --git a/app/views/students/new.html.erb b/app/views/students/new.html.erb index 2d3436368..6394145bb 100644 --- a/app/views/students/new.html.erb +++ b/app/views/students/new.html.erb @@ -1 +1 @@ -<%= render 'form' %> +<%= render partial: 'form', :locals => { student: @student } %> diff --git a/app/views/students/show.html.erb b/app/views/students/show.html.erb index aefa0b5c4..d18328b55 100644 --- a/app/views/students/show.html.erb +++ b/app/views/students/show.html.erb @@ -1,3 +1,4 @@

Student Info

-<%= render 'student' %> +<%= render partial: 'student', locals: {student: @student} %> + diff --git a/db/schema.rb b/db/schema.rb index a8f1d5d04..682993151 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. diff --git a/spec/controllers/students_controller_spec.rb b/spec/controllers/students_controller_spec.rb deleted file mode 100644 index fbf299f84..000000000 --- a/spec/controllers/students_controller_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'rails_helper' - -RSpec.describe StudentsController, type: :controller do - describe 'students#index' do - describe 'when passed a search query on the "query" parameter' do - render_views - - it 'only renders items that match the query' do - b = Faker::Date.between(from: 25.years.ago, to: 18.years.ago) - Student.create(name: 'Byronius Karbitus Maris', hometown: "San Francisco", birthday: b) - Student.create(name: 'Notorious Byron', hometown: "Brooklyn", birthday: b) - Student.create(name: 'Blah Byron Blah', hometown: "Manhattan", birthday: b) - Student.create(name: 'King Zebra', hometown: "New Prussia", birthday: b) - - get :index, params: { query: "Byron" } - - expect(response.body).not_to match(/Zebra/) - end - end - end - -end