简体   繁体   中英

In Rails, what's the difference between to_label and to_s?

In Rails, what's the difference between to_label and to_s ? Especially in the context of displaying model info in views. I know that if you define to_s you don't have to explicitly call Model.to_s in views. What's the advantage of using to_label then?

to_label has been deprecated, you can't find it from the Rails3 source

I believe the difference was that to_label did some magic in that converting values such as object class names to_s where as to_s just converts an object to a string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM