来自 Controller 名称的模型类

你可以通过这种方式从 Controller 名称获取 Model 类(上下文是 Controller 类):

class MyModelController < ActionController::Base

  # Returns corresponding model class for this controller
  # @return [ActiveRecord::Base]
  def corresponding_model_class
    # ... add some validation
    controller_name.classify.constantize
  end
end