controller_name classify constantize model_name

控制器

class CourseSurveysController < ResourcesBaseController

end

 

controller_name   # "course_surveys"
controller_name.singularize  # "course_survey"
controller_name.singularize.classify  # "CourseSurvey"

 

'Module'.constantize     # => Module(没"",不是字符串)
'Test::Unit'.constantize    # => Test::Unit(没"",不是字符串)

 

class Person < ActiveModel::Model
end

Person.model_name          # => Person
Person.model_name.class    # => ActiveModel::Name
Person.model_name.singular # => "person"
Person.model_name.plural   # => "people"

 

posted @ 2015-02-04 14:46  tardis  阅读(319)  评论(0编辑  收藏  举报