Ruby on Rails Naming Conventions Models class from Controller name


Example

You can get a Model class from a Controller name this way (context is Controller class):

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