Giter VIP home page Giter VIP logo

rails-url-helpers-lab's Introduction

Rails URL Helpers Lab

Objectives

  1. Generate URLs using route helpers
  2. Draw routes with implicit and explicit names using :as
  3. Draw routes with variables
  4. Generate URLs using route helpers that require variables

Instructions

In this lab you will be building out the Student management dashboard for the Flatiron School by starting to integrate the ability to link between pages. Two tests are currently passing, and the rest need implementation code to start passing. In order to complete this lab, you will need to complete the following tasks:

  • A user should be able to navigate to /students to view all of the students.
  • A user should be able to click the student's name on the index page and be taken to that specific student's show page.
  • Create a new boolean attribute called active in the students table. (HINT: You might have to search around for the best way to set a (ahem) default value (should default to false).)
  • A user should be able to go to /students/:id/activate to toggle their active attribute between true and false. (This is just the activate route, and not a actual view.)
  • Read the failing tests and modify the code until they pass.

Keep in mind

  • Make sure the show path is /students/:id, where :id is a route variable.
  • Call the Student class instance method to_s on each of the students on the index page so that each student element contains their first and last name.
  • On the student index page, test out all three different link_to argument options, e.g.: link_to "post", "/post/#{post.id}", link_to("post", post_path(post.id)), link_to("post", post_path(post)).

Resources

rails-url-helpers-lab's People

Contributors

annjohn avatar bacitracin avatar bhollan avatar brennenawana avatar danielseehausen avatar drakeltheryuujin avatar genericlady avatar humzahchoudry avatar ihollander avatar interestinall avatar ipc103 avatar jmburges avatar jordanhudgens avatar maxwellbenton avatar nikymorg avatar pletcher avatar realandrewcohn avatar rrcobb avatar sdcrouse avatar survivingknowledge avatar victhevenot avatar

Watchers

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

rails-url-helpers-lab's Issues

Suggestion for "activate page" clarity

Issue : Confusion due to spec/recent labs+readings

Reasoning : The spec uses "Activate page" alongside the index and show pages, which makes it seem like the "activate page" is an actual html.erb view (as those views are what has been discussed in all of the recent labs/readings).

Suggestion : Make it clearer that the "activate page" is actually just the "activate route" and not an actual view.

A small edit to the README is needed

I am guessing that this lab has been updated recently. The README needs to be ever-so-slightly updated.

It says that "four tests are currently passing". However, when I first ran learn on this lab, only TWO tests were passing: "Student can be created" and "Student has a to_s instance method".

As far as I can tell right now, that's the only thing that needs to be fixed. Thanks for looking into this!

Update: I just fixed this in a pull request.

---Sdcrouse

student_path(@student) used in the tests for navigation is undefined

spec\features\student_spec.rb

Rails.application.routes.draw do
  resources :students, only: :index

  # This show route can be refactored into the above resources method call, like so:
  # resources :students, only: [:index, :show]
  # However, for the sake of this lab and seeing how you can pass params through
  # the route, we'll keep it explicit for now and refactor later.
  get "students/:id", to: "students#show"
end

These comments imply that line 2 and 8 are the equivalent to line 5 when in reality the method student_path (used in the tests) isnt generated by line 2 or 8, only on line 5.

test

  it 'renders properly' do
    visit student_path(@student)
    expect(page.status_code).to eq(200)
  end

Can't do lab - broken every step of way

Comes in broken. Bundle install? NAHHHH

Dans-MacBook-Pro:module2 danparry$ git clone [email protected]:parryd4/rails-url-helpers-lab-web-040317.git
Cloning into 'rails-url-helpers-lab-web-040317'...
remote: Counting objects: 319, done.
remote: Compressing objects: 100% (167/167), done.
remote: Total 319 (delta 113), reused 319 (delta 113), pack-reused 0
Receiving objects: 100% (319/319), 456.61 KiB | 0 bytes/s, done.
Resolving deltas: 100% (113/113), done.
Dans-MacBook-Pro:module2 danparry$ cd rails-url-helpers-lab-web-040317/
Dans-MacBook-Pro:rails-url-helpers-lab-web-040317 danparry$ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.3
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile 0.6.2
Using rack 1.6.4
Using mime-types 2.6.2
Using arel 6.0.3
Using debug_inspector 0.0.2
Using byebug 8.2.0
Using coffee-script-source 1.10.0
Using execjs 2.6.0
Using thor 0.19.1
Using database_cleaner 1.5.1
Using diff-lcs 1.2.5
Using multi_json 1.11.2
Using bundler 1.14.6
Using rspec-support 3.0.4
Using sass 3.4.19
Using tilt 2.0.1
Using spring 1.4.1
Using sqlite3 1.3.11
Using rdoc 4.2.0
Using tzinfo 1.2.2
Installing nokogiri 1.6.6.2 with native extensions
Using rack-test 0.6.3
Using sprockets 3.4.0
Using mail 2.6.3
Using binding_of_caller 0.7.2
Using coffee-script 2.4.1
Using uglifier 2.7.2
Using rspec-core 3.0.4
Using rspec-expectations 3.0.4
Using rspec-mocks 3.0.4
Using sdoc 0.4.1
Using activesupport 4.2.3
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/nokogiri-1.6.6.2/ext/nokogiri
/Users/danparry/.rvm/rubies/ruby-2.3.0/bin/ruby -r
./siteconf20170501-914-urj9ix.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts
-Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.

The file "/usr/include/iconv.h" is missing in your build environment,
which means you haven't installed Xcode Command Line Tools properly.

To install Command Line Tools, try running xcode-select --install on
terminal and follow the instructions. If it fails, open Xcode.app,
select from the menu "Xcode" - "Open Developer Tool" - "More Developer
Tools" to open the developer site, download the installer for your OS
version and run it.

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/danparry/.rvm/rubies/ruby-2.3.0/bin/$(RUBY_BASE_NAME)
--help
--clean
--use-system-libraries
--enable-static
--disable-static
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--enable-cross-build
--disable-cross-build

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

/Users/danparry/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-16/2.3.0/nokogiri-1.6.6.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/nokogiri-1.6.6.2 for inspection.
Results logged to
/Users/danparry/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-16/2.3.0/nokogiri-1.6.6.2/gem_make.out

An error occurred while installing nokogiri (1.6.6.2), and Bundler
cannot continue.
Make sure that gem install nokogiri -v '1.6.6.2' succeeds before bundling.

**OK. I'll use bundle update, because Gemfiles?

Dans-MacBook-Pro:rails-url-helpers-lab-web-040317 danparry$ bundle update**
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 12.0.0 (was 10.4.2)
Using i18n 0.8.1 (was 0.7.0)
Using json 1.8.6 (was 1.8.3)
Using minitest 5.10.1 (was 5.8.3)
Using thread_safe 0.3.6 (was 0.3.5)
Using builder 3.2.3 (was 3.2.2)
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using rack 1.6.5 (was 1.6.4)
Using mime-types-data 3.2016.0521
Using arel 6.0.4 (was 6.0.3)
Using public_suffix 2.0.5
Using debug_inspector 0.0.2
Using bundler 1.14.6
Using byebug 9.0.6 (was 8.2.0)
Using coffee-script-source 1.12.2 (was 1.10.0)
Using execjs 2.7.0 (was 2.6.0)
Using thor 0.19.4 (was 0.19.1)
Using concurrent-ruby 1.0.5
Using database_cleaner 1.5.3 (was 1.5.1)
Using diff-lcs 1.3 (was 1.2.5)
Using multi_json 1.12.1 (was 1.11.2)
Using rdoc 4.3.0 (was 4.2.0)
Using rspec-support 3.0.4
Using sass 3.4.23 (was 3.4.19)
Using tilt 2.0.7 (was 2.0.1)
Using sqlite3 1.3.13 (was 1.3.11)
Using turbolinks-source 5.0.0
Using tzinfo 1.2.3 (was 1.2.2)
Using nokogiri 1.7.1 (was 1.6.6.2)
Using rack-test 0.6.3
Using mime-types 3.1 (was 2.6.2)
Using addressable 2.5.1
Using binding_of_caller 0.7.2
Using coffee-script 2.4.1
Using uglifier 3.2.0 (was 2.7.2)
Using sprockets 3.7.1 (was 3.4.0)
Using sdoc 0.4.2 (was 0.4.1)
Using rspec-core 3.0.4
Using rspec-expectations 3.0.4
Using rspec-mocks 3.0.4
Using turbolinks 5.0.1 (was 2.5.3)
Using activesupport 4.2.3
Using loofah 2.0.3
Using xpath 2.0.0
Using mail 2.6.5 (was 2.6.3)
Using rails-deprecated_sanitizer 1.0.3
Using globalid 0.4.0 (was 0.3.6)
Using activemodel 4.2.3
Using factory_girl 4.8.0 (was 4.5.0)
Using jbuilder 2.6.3 (was 2.3.2)
Using spring 2.0.1 (was 1.4.1)
Using rails-html-sanitizer 1.0.3 (was 1.0.2)
Using capybara 2.13.0 (was 2.5.0)
Using rails-dom-testing 1.0.8 (was 1.0.7)
Using activejob 4.2.3
Using activerecord 4.2.3
Using actionview 4.2.3
Using actionpack 4.2.3
Using actionmailer 4.2.3
Using railties 4.2.3
Using sprockets-rails 3.2.0 (was 2.3.3)
Using coffee-rails 4.1.1 (was 4.1.0)
Using factory_girl_rails 4.8.0 (was 4.5.0)
Using jquery-rails 4.3.1 (was 4.0.5)
Using rspec-rails 3.0.2
Using rails 4.2.3
Using sass-rails 5.0.6 (was 5.0.4)
Using web-console 2.3.0 (was 2.2.1)
Bundle updated!

**Great. Should be ok.

Dans-MacBook-Pro:rails-url-helpers-lab-web-040317 danparry$ learn**
Web Console is activated in the test environment, which is
usually a mistake. To ensure it's only activated in development
mode, move it to the development group of your Gemfile:

gem 'web-console', group: :development

If you still want to run it the test environment (and know
what you are doing), put this in your Rails application
configuration:

config.web_console.development_only = false

**But it came this way:

Gemfile:
...
group :development, :test do
gem 'byebug'
gem 'web-console', '> 2.0'
gem 'spring'
gem 'rspec-rails', '
> 3.0.0'
gem 'factory_girl_rails'
gem 'capybara'
gem 'database_cleaner'
end

So I'll follow the suggestion, change it to:

group :development, :test do
gem 'byebug'
gem 'spring'
gem 'rspec-rails', '~> 3.0.0'
gem 'factory_girl_rails'
gem 'capybara'
gem 'database_cleaner'
end

gem 'web-console', '~> 2.0', group: :development

and run try Learn again

Dans-MacBook-Pro:rails-url-helpers-lab-web-040317 danparry$ learn**
Array values in the parameter to Gem.paths= are deprecated.
Please use a String or nil.
An Array ({"GEM_PATH"=>["/Users/danparry/.rvm/gems/ruby-2.3.0", "/Users/danparry/.rvm/gems/ruby-2.3.0@global"]}) was passed in from bin/rake:3:in `load'
Web Console is activated in the test environment, which is
usually a mistake. To ensure it's only activated in development
mode, move it to the development group of your Gemfile:

gem 'web-console', group: :development

If you still want to run it the test environment (and know
what you are doing), put this in your Rails application
configuration:

config.web_console.development_only = false

/Users/danparry/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:392:in `check_pending!': (ActiveRecord::PendingMigrationError)

Migrations are pending. To resolve this issue, run:

bin/rake db:migrate RAILS_ENV=test

from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:405:in `load_schema_if_pending!'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:411:in `block in maintain_test_schema!'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:639:in `suppress_messages'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:416:in `method_missing'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:411:in `maintain_test_schema!'
from /Users/danparry/Development/code/module2/rails-url-helpers-lab-web-040317/spec/rails_helper.rb:19:in `<top (required)>'
from /Users/danparry/Development/code/module2/rails-url-helpers-lab-web-040317/spec/features/student_spec.rb:2:in `require'
from /Users/danparry/Development/code/module2/rails-url-helpers-lab-web-040317/spec/features/student_spec.rb:2:in `<top (required)>'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `block in load_spec_files'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `each'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load_spec_files'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:97:in `setup'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
from /Users/danparry/.rvm/gems/ruby-2.3.0/bin/rspec:22:in `load'
from /Users/danparry/.rvm/gems/ruby-2.3.0/bin/rspec:22:in `<main>'
from /Users/danparry/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
from /Users/danparry/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'

**Following the advice didn't fix the problem. But it got me a step farther, by telling me to "rake db:migrate RAILS_ENV=test"
So. Lets try that.

Dans-MacBook-Pro:rails-url-helpers-lab-web-040317 danparry$ rake db:migrate RAILS_ENV=test**
rake aborted!
NoMethodError: undefined method last_comment' for #<Rake::Application:0x007fef1fa36838> /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/lib/rspec/core/rake_task.rb:101:in define'
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.0.4/lib/rspec/core/rake_task.rb:78:in initialize' /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-rails-3.0.2/lib/rspec/rails/tasks/rspec.rake:11:in new'
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-rails-3.0.2/lib/rspec/rails/tasks/rspec.rake:11:in <top (required)>' /Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-rails-3.0.2/lib/rspec-rails.rb:13:in load'
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/rspec-rails-3.0.2/lib/rspec-rails.rb:13:in block in <class:Railtie>' /Users/danparry/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/railtie.rb:237:in instance_exec'
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/railtie.rb:237:in block in run_tasks_blocks' /Users/danparry/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/railtie.rb:245:in each'
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/railtie.rb:245:in each_registered_block' /Users/danparry/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/railtie.rb:237:in run_tasks_blocks'
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/application.rb:451:in block in run_tasks_blocks' /Users/danparry/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/engine/railties.rb:13:in each'
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/engine/railties.rb:13:in each' /Users/danparry/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/application.rb:451:in run_tasks_blocks'
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:453:in load_tasks' /Users/danparry/Development/code/module2/rails-url-helpers-lab-web-040317/Rakefile:6:in <top (required)>'
/Users/danparry/.rvm/gems/ruby-2.3.0/gems/rake-12.0.0/exe/rake:27:in <top (required)>' /Users/danparry/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in eval'
/Users/danparry/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `

'
(See full trace by running task with --trace)

OK. Guess I'm not doing this lab.

Issues with secrets.yml

Students have been receiving error upon opening this lab, that they didn't set their secret token in the secrets.yml file:

DEPRECATION WARNING: You didn't set secret_key_base. Read the upgrade documentation to learn more about this new config option. (called from get at /Users//.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/forwardable.rb:183)
has an index page (FAILED - 1)

Multiple students
DEPRECATION WARNING: You didn't set secret_key_base. Read the upgrade documentation to learn more about this new config option. (called from get at /Users//.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/forwardable.rb:183)
shows them on the index page

Students have been googling and creating their own secrets.yml file, setting the secret token to resolve the issue.

The "activate page" part needs to be modified or removed

Hi. I got a little stuck when going through this lab.

When I got to the "activate page" part, it became clear that I needed to redirect to the '/students/:id' route after toggling the student's "active" status on or off. There was just one problem: none of the lessons up to this point have covered how to redirect with Rails (unless that was introduced in the Video Review near the start of the Rails module). I was able to figure it out after some research, thankfully.

I'm not sure whether the "activate page" part should be modified or removed altogether. I'm guessing that its purpose was to have us practice using the :as option in our routes. Either way, thanks a lot for looking into this!

---Sdcrouse

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.