learn-co-curriculum / partial-locals-lab Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
Failures:
Student search when it receives a search query returns all students whose names contain the given string
Failure/Error: <%= form_tag students_path, method: :get do %>
ActionView::Template::Error:
undefined local variable or method `students_path' for #<#Class:0x000055ea769a2b38:0x000055ea75e86b00>
Did you mean? @Students
This was also casuing 7 other tests to fail for the exact same reason.
Once adding routes in for students and classrooms
Rails.application.routes.draw do
resources :classrooms
resources :students
end
It passed all tests.
The lab never specifically mentions needing to create routes, and im not sure if it has other interactions with the previous tests given i was forced to use the solution branch to try to figure out why what looked to be correct code kept failing.
Just to echo all the previous issues, the instructions to "implement search functionality" leave us guessing what the tests are actually looking for. The tests end up not even looking for something that will actually work for an end user.
You could add something simple in to make it work for the end user, for example, the path http://localhost:3000/students/?search=QUERY can be used to set @Students in the index controller by whether or not params[:search]
is nil (ie Student.all
vs Student.search(params[:search])
. That path will already automatically be routed to the students#index
action. This easily works visually in the browser and a few sentences explaining it will help students understand what the requirements are rather than digging through the spec files.
One of the reasons it is confusing is because search functionality is never actually implemented beyond the model.
Thanks!
you can pass all of the tests without actually building the search feature. if you have partials for _student and render that partial on the student index page, plus .search
method in Student class, you can pass tests without building /students/search
route, #search
method in students controller, search for on students index page.
There was an update to the Faker gem that requires the keywords 'from' and 'to" in order for rake db:seed to work. Update the code in the db/seeds.rb file to match the below
80.times do Student.create(name: Faker::Name.name, hometown: Faker::Address.city, birthday: Faker::Date.between(from: 25.years.ago, to: 18.years.ago)) end
The student_index_spec.rb
file checks for the presence of a search method and rendering of a partial--but there isn't a check to see that the search is actually implemented as described by the README ("Second, they also want to add some search functionality so that a user can search for a student by name. It's okay if other students with similar names are returned in the search results.")
It's possible to pass all specs for this lab without updating student#index in student_controller.rb
to use the model's search method. i.e., leaving student#index defined as @students = Student.all
. When rendered in-browser, though, the search form doesn't actually work. Not sure what test could be added...maybe one that visits students/index, fills the search form with a name, then checks that the last response does not include a name that wouldn't otherwise be returned?
The following lines make it seem as though we need to set up a form or somehow receive user input on the students/show or students/index pages. However, this is not necessary and so the instructions are really confusing regarding what specifically we need to do, or what the desired end result is:
add some search functionality so that a user can search for a student by name. It's okay if other students with similar names are returned in the search results.
Add in search functionality such that users can search for a student by name and see all matching results on the students index page. The results should be displayed by rendering a students/_student.html.erb partial.
@blake41 isn't that a weird pattern? I've always just passed in @student
as a local instead of the f
Missing keywords :from and :to in the 80.times do block
Currently:
80.times do
Student.create(name: Faker::Name.name, hometown: Faker::Address.city, birthday: Faker::Date.between(25.years.ago, 18.years.ago))
end
Should be:
80.times do
Student.create(name: Faker::Name.name, hometown: Faker::Address.city, birthday: Faker::Date.between(from: 25.years.ago, to: 18.years.ago))
end
For the classroom#show view using the student partial, I set up my classroom controller like so:
def show
@classroom = Classroom.find(params[:id])
@Students = @classroom.students
end
I then iterated through @Students and used each individual student in the student partial. While this works in my browser as expected, the tests failed and kept giving me an error that @Students was nil. Testing it in pry and the console showed that @classroom.students gave me back a full list of students, and it showed all students in the browser.
The only way I could pass the tests was to use @classroom.students.each to iterate on the show page rather than passing the @Students variable I created in the controller. A technical coach helped me figure out the problem and suggested that it could be something specific in the tests that is not allowing the use of a variable @Students.
The method we are required to write requires knowledge of SQL "LIKE operator". Maybe there should be a hint about search queries. Otherwise, bullet point 5 is a bit out of nowhere.
The "Faker" that is used to create data for tests, sometimes generates student names with special characters that make the test fail since the views don't have the correct encoding.
Image of a test failing with the name "Miss Emerald O'Keefe"
classroom_show_view
renders classroom information on the show view
renders a partial that only contains classroom (not student) information
renders a students/student partial
displays the student information from the partial
but
`
Classroom Info
<%= render partial: "classrooms/classroom", locals: {classroom: @classroom} %>
We now want to call out the oldest student in the class:
<% @classroom.students.each do |student| %>
<%= render partial: 'students/student', locals: {student: student} %>
<% end %>
##14
`
It appears to me that the lesson requests a search for classrooms, but the tests are for a search for student names.
I believe the way the spec is written is a little bottle-necky. The tests only pass if the @students
variable is iterated through, versus using collections notation i.e. <%= render partial: "student", collection: @students %>
. Don't they do the same thing?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.