Ask A Question


You’re not receiving notifications from this thread.

Pair Programming on Rails Scopes Discussion

For your business days scope, could you not use to keep it all ruby and DB agnostic, rather than using EXTRACT? (


The EXTRACT is required because you need something to pull out the week day inside the database so you can make the comparison. The Ruby method unfortunately can't help you here because this is running a query inside the database.


Are you going to do more pair programming videos in the future? This and the one where you're fixing a bug in Devise are my favourites.


Definitely planning to! I think it helps explain things a lot better with the discussion.


This sort of tutorial is really so helpful. It would have been more nice if we could watch how to change default week days and starting week day in rails.


When I try to follow and enter these commands into irb, I keep getting the following errors. Any idea what I am doing wrong?

2.7.0 :002 >
Traceback (most recent call last):
5: from /Users/charles/.rvm/rubies/ruby-2.7.0/bin/irb:23:in <main>'
4: from /Users/charles/.rvm/rubies/ruby-2.7.0/bin/irb:23:in
3: from /Users/charles/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in <top (required)>'
2: from (irb):1
1: from (irb):2:in
rescue in irb_binding'
NoMethodError (undefined method `zone' for Time:Class)


Hey Charles, comes from ActiveSupport, so you'll need to either do this in the Rails console or require "active_support/all" in your IRB session.


Ok got it, thanks for the really quick response Chris.


Maybe I'm doing something else wrong?

2.7.0 :001 > require "active_support/all"
=> true
2.7.0 :002 > Event.current_month
Traceback (most recent call last):
4: from /Users/charles/.rvm/rubies/ruby-2.7.0/bin/irb:23:in <main>'
3: from /Users/charles/.rvm/rubies/ruby-2.7.0/bin/irb:23:in
2: from /Users/charles/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `'
1: from (irb):2
NameError (uninitialized constant Event)
2.7.0 :003 >


I know this is old, but going to answer anyway for future users. You have not defined "Event" here so it doesn't know what to do with that. Try something like:

irb(main):007:1* class Event
irb(main):008:0> end
=> nil
irb(main):009:0> event =
=> #<Event:0x000000011b86db18>
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 79,047+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.