Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where in Rails should I modify a base class?

I want to change Fixnum to include the a "weekend_days" method:

class Fixnum

  def weekend_days
    //get correct days
  end

end

I want this available in my controllers and models? Obviously, I also need it to work in my tests.

Where is the "rails" appropriate place to put this?

like image 334
Todd R Avatar asked Dec 17 '25 15:12

Todd R


1 Answers

My inclination would be to simply stick this into config/initializers/fixnum.rb. Rails will automatically pick this up during the startup process, so it should be available in the actual app, tests, etc. If you end up using this in several Rails projects, a plugin might be a good choice, too.

like image 157
Mirko Froehlich Avatar answered Dec 19 '25 05:12

Mirko Froehlich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!