來自 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