Ask A Question

Notifications

You’re not receiving notifications from this thread.

Pair Programming on Rails Scopes Discussion

For your business days scope, could you not use Time.now.wday to keep it all ruby and DB agnostic, rather than using EXTRACT? (http://ruby-doc.org/core-2....

Reply

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.

Reply

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.

Reply

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

Reply

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.

Reply

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 > Time.zone.now
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
load'
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)

Reply

Hey Charles,

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

Reply

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

Reply

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
load'
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 >

Reply

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.new
=> #<Event:0x000000011b86db18>
Reply
Join the discussion
Create an account Log in

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

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

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