I have a Rails application that generates a weekly report and emails it out. I don't want the production app to have any sort of web interface, for security and convenience reasons (don't want to maintain a web interface).
However, I do have a rudimentary web interface to the database that I'd like to keep available in my development environment for debugging, etc.
Is there an easy way to make the controller methods invalid unless I'm in the development rails environment?
A good approach would be the following:
class MyController < ActionController::Base
before_filter :restrict_to_development, :only => [:user_report]
def index
...
end
def user_report
...
end
protected
# this method should be placed in ApplicationController
def restrict_to_development
head(:bad_request) unless Rails.env.development?
end
end
Because ruby's classes are evaluated as they are read, you can do this:
class MyController < ActionController::Base
if RAILS_ENV == "development"
def index
#...
end
end
end
The index method should only be available when running in development mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With