5

In my model I would like to check if the app is running inside IRB consol or as a website?

class MyModel < ActiveRecord::Base
  def xmethod
    if !isIRBconsol
      self.user_id = UserSession.find.user.id
    end
  end
end
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
xpepermint
  • 35,055
  • 30
  • 109
  • 163

3 Answers3

4

Why not just if defined?(IRB)?

indirect
  • 3,470
  • 2
  • 25
  • 13
  • 2
    This doesn't seem to always work depending on your scope, I've settled on `Rails.const_defined?('Console')` for now. – toupeira Nov 15 '13 at 14:58
3

This is a bit of a hack, but it should work:

class MyModel < ActiveRecord::Base
  def am_i_in_irb?
    self.private_methods.include? 'irb_binding'
  end
end

But as Kathy Van Stone said above, this is probably something that has a better solution.

Josh Lindsey
  • 8,455
  • 3
  • 24
  • 25
0
unless self.private_methods.include? 'irb_binding'
   #put your rufus scheduling here
end
msmukesh4
  • 589
  • 4
  • 7