xpepermint
xpepermint

Reputation: 36273

Rails check if IRB console or webpage

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

Upvotes: 5

Views: 1372

Answers (3)

msmukesh4
msmukesh4

Reputation: 589

unless self.private_methods.include? 'irb_binding'
   #put your rufus scheduling here
end

Upvotes: 0

indirect
indirect

Reputation: 3490

Why not just if defined?(IRB)?

Upvotes: 4

Josh Lindsey
Josh Lindsey

Reputation: 8813

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.

Upvotes: 3

Related Questions