我有一个Rails应用程序,可以生成每周报告并通过电子邮件发送出去。出于安全性和便利性的原因,我不希望生产应用程序有任何类型的web界面(不想维护web界面)。
但是,我确实有一个到数据库的基本web界面,我希望在我的开发环境中保持可用,以便进行调试等。
有没有一种简单的方法让控制器方法失效,除非我在开发rails环境中?
发布于 2009-07-30 20:07:34
一种好的方法是:
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发布于 2009-07-30 15:59:05
因为ruby的类是在读取时计算的,所以您可以这样做:
class MyController < ActionController::Base
if RAILS_ENV == "development"
def index
#...
end
end
end索引方法应仅在以开发模式运行时可用。
发布于 2009-07-30 22:25:49
简单地创建另一个共享相同模型定义并提供web界面的rails应用程序可能是有意义的。这样,您就不会冒险将任何特殊情况的代码推送到生产环境中,而且您的生产应用程序也会变得更小。
https://stackoverflow.com/questions/1207424
复制相似问题