Giter Site home page Giter Site logo

rails-restful-index-action-lab's Introduction

RESTful Index Action Lab

Objectives

  1. Draw a get route
  2. Map a route to a controller action
  3. Define a controller action
  4. Load instances from ActiveRecord into a controller instance variable
  5. Render a template
  6. Use an instance variable from a controller action in a template
  7. Iterate over an ActiveRecord collection in ERB
  8. Build a classical index action/view

RESTful Routes

In this lab you will walk through how to build each element required to render a list of students out in the browser. The RSpec/Capybara tests for this lab can be found in spec/features. Both tests should be passing to complete the lab.

Note If you run into an ActiveRecord::PendingMigration error when you run the tests, try rake db:migrate RAILS_ENV=test in the terminal then run the tests again.

Instructions

  • Run bundle install from your terminal

  • Create a controller for students and have it inherit from ApplicationController

  • Create a route for the path /students that maps to a StudentsController index action.

  • Add a controller action to the StudentsController named index

  • Have the new index action pull in a list of all of the students with Student.all and store it in an instance variable

  • Create an index.html.erb view file and render it from your Students#index action. The index.html.erb file should be placed within a views/students folder.

  • In your view, iterate over the list of students returned from the index action in the controller and display the appropriate information.

Resources

rails-restful-index-action-lab's People

Contributors

annjohn avatar chromeboi avatar cs-j avatar danielseehausen avatar dependabot[bot] avatar drakeltheryuujin avatar ihollander avatar jmburges avatar jordanhudgens avatar lizbur10 avatar maxwellbenton avatar meg-gutshall avatar paulnicholsen27 avatar pletcher avatar realandrewcohn avatar rocketneck avatar rrcobb avatar sgharms avatar sylwiavargas avatar yberdysh avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rails-restful-index-action-lab's Issues

Viewing the index page raises an error

When attempting to view the index page It's showing undefined method '+' for nil:NilClass. Looks like the db comes with a record that contains several attributes set to nil.

For #to_s (Student class), instead of self.first_name + " " + self.last_name, changing it to
"#{self.first_name} #{self.last_name}" prevents the error.

RE-EDIT: student_index_spec.rb

`describe 'Multiple students are shown' do
it 'on the index page' do
Student.create!(first_name: "Daenerys", last_name: "Targaryen")
Student.create!(first_name: "Lindsey", last_name: "Stirling")

visit "/students"

expect(page).to have_content(/(?=.*Daenerys)(?=.*Lindsey).*/)

end`

Okay! So changing "expect(page).to have_content(/(?=.*Daenerys)|(?=.Lindsey)./)"
to: "expect(page).to have_content(/(?=.*Daenerys)(?=.Targaryen)./)"
is Not the answer. I'm sorry.
What I found though was that that line of code is missing a ' | '; so:
"expect(page).to have_content(/(?=.*Daenerys)|(?=.Lindsey)./)".

Sorry. For the mix up. The test passed this way, and it makes more since adding this ' | ' instead of changing the name. So this way it checks for both names.

-Alex

Instructions Do Not Match or Pass RSPEC

Current Instruction: Map an index.html.erb view file to the student controller and iterate over the list of students returned from the index action in the controller

Correction: students.html.erb

Confusing instructions.

Instructions call for placing the index.html.erb file within a view/students folder, but Capybara tests expect it to be placed in a student folder (singular).

assert_text error

tests used to have assert_text('Daenerys', 'Lindsey')

but I was getting this error:

Failures:

  1) Multiple students are shown on the index page
     Failure/Error: assert_text('Daenerys', 'Lindsey')
     
     ArgumentError:
       Daenerys is not a valid type for a text query

until we made this change:

assert_text('Daenerys Targaryen') assert_text('Lindsey Stirling')

student_index_spec.rb

describe 'Multiple students are shown' do
it 'on the index page' do
Student.create!(first_name: "Daenerys", last_name: "Targaryen")
Student.create!(first_name: "Lindsey", last_name: "Stirling")

visit "/students"

expect(page).to have_content(/(?=.*Daenerys)(?=.*Lindsey).*/)

end
end

I--------------I
I believe that the line:
'expect(page).to have_content(/(?=.*Daenerys)(?=.Lindsey)./)'
should maybe be:
'expect(page).to have_content(/(?=.*Daenerys)(?=.Targaryen)./) .

That was the only way I was able to pass the test. Unless I'm wrong. Then I have no idea what I did..

-Alex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.