learn-co-curriculum / phase-3-active-record-intro-to-rake

Other
1 stars 2.51k forks source link

Last 'Pry' Based Rake Task Is Flawed #9

Open SamuelBanya opened 2 years ago

SamuelBanya commented 2 years ago

Canvas Link

https://learning.flatironschool.com/courses/5286/assignments/172676?module_item_id=376756

Concern

Here's my entire script:

# NOTE: If we then use the command, 'rake hello' in another terminal, we the return the 'puts' output below
# It's basically Ruby's version of the 'Makefile' / Crontab jobs

# NOTE: By adding a 'namespace', we can group our related Rake tasks together:
namespace :greeting do

  # NOTE: If we use 'rake -T', this will list the available 'Rake' tasks and their descriptions:
  desc 'outputs hello to the terminal'
  task :hello do
    puts "hello from Rake!"
  end

  desc 'outputs hola to the terminal'
  task :hola do
    puts "hola desde Rake!"
  end

end

# NOTE: We can use these individual tasks using the 'namespace:rake_task' syntax:
# rake greeting:hello
# rake greeting:hola

# NOTE: If you encounter this error:
# rake aborted!
# Gem::LoadError: You have already activated rake 10.4.2,
# but your Gemfile requires rake 10.4.0.
# Prepending `bundle exec` to your command may solve this.

# Then, use this command as the fix:
# bundle exec rake greeting:hello

# NOTE: We will now use the 'rake db:migrate' command to create a database table and migrate the code using
# a 'rake' task:

namespace :db do
  task :environment do
    require_relative "./config/environment"
  end

  desc "migrate changes to your database"
  # NOTE: This line creates a task dependency to force the rake task to run the ':environment' task
  # BEFORE running the 'migrate' task:
  task migrate: :environment do
    Student.create_table
  end

  desc "seed the database with some dummy data"
  task seed: :environment do
    require_relative "./db/seeds"
  end
end

desc "drop into the Pry console"
task console: :environment do
  Pry.start
end

If I run the 'bundle exec rake console' command after running the 'rake db:migrate' and 'rake db:seed' commands respectively, I get this error:

samuelbanya@Samuels-MBP ~/hub/Development/code/phase-3/phase-3-active-record-intro-to-rake $ bundle exec rake console
rake aborted!
Don't know how to build task 'environment' (See the list of available tasks with `rake --tasks`)
Did you mean?  db:environment
/Users/samuelbanya/.gem/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/cli/exec.rb:63:in `load'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/cli/exec.rb:63:in `kernel_load'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/cli/exec.rb:28:in `run'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/cli.rb:474:in `exec'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/cli.rb:30:in `dispatch'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/cli.rb:24:in `start'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/exe/bundle:49:in `block in <top (required)>'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/lib/bundler/friendly_errors.rb:128:in `with_friendly_errors'
/Users/samuelbanya/.gem/gems/bundler-2.2.23/exe/bundle:37:in `<top (required)>'
/Users/samuelbanya/.rvm/gems/ruby-2.7.4/bin/bundle:25:in `load'
/Users/samuelbanya/.rvm/gems/ruby-2.7.4/bin/bundle:25:in `<main>'
/Users/samuelbanya/.rvm/gems/ruby-2.7.4/bin/ruby_executable_hooks:22:in `eval'
/Users/samuelbanya/.rvm/gems/ruby-2.7.4/bin/ruby_executable_hooks:22:in `<main>'
Tasks: TOP => console
(See full trace by running task with --trace)

Additional Context

No response

Suggested Changes

No response

SamuelBanya commented 2 years ago

UPDATE:

This section is the issue with this lab --> Nowhere is the following section mentioned that this is needed outside of the ':db' namespace:

task :environment do
  require_relative "./config/environment"
end

This part alone needs to be added to the lab for people to pass it without needing to refer to the solution branch.