ActiveSupport::CoreExtensions::String::Inflections
classify()&&contantize()
四种方法,假设str是类名:
obj=eval(str).new
obj=eval"obj=#{str}.new"
c=Object.const_get("Array")
s=c.new
eval"obj=#{str}.new" # 只能在irb中使用
# post: /material_attributes/destroy_material_attributes.json
# 根据传过来的参数删除物料基础属性的记录
def destroy_material_attributes
params[:mType].constantize.destroy(params[:mId])
render_json ' '
end
使用contantize()方法相当于java中的方法重载,其传递进来的字符串'params[:mType]'转为类,类与表名相对应,然后调用共同的方法destroy(params:[:mId]).