新手问题 求教如何把 string 转 model 的方法

kitt · November 29, 2012 · Last by ashchan replied at November 29, 2012 · 2976 hits

比如有个字符串“User”,如果我想把它转换成 model 名,该怎么做呢,

Rails 里面

"User".constantize

操,太感谢楼上的了,解了我的燃眉之急,衷心的感谢,嘿嘿,非常感谢

纯 Ruby 的话用 Kernel.const_get 'User'

You need to Sign in before reply, if you don't have an account, please Sign up first.