views:

114

answers:

4

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?

+1  A: 

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.

erik
+6  A: 

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
BigCanOfTuna
A: 

It might make sense to simply make another rails application that shares the same model definitions and offers the web interface. This way, you don't risk pushing any special-case code to production and your production application is smaller.

Duncan Beevers
+1  A: 

if you are using passenger you can do something like this

ServerName mysite.com DocumentRoot /home/user/project/public RailsEnv development

this will only make the development available.

Ranchersam