Understanding usage of symbols in routes.rb files

大城市里の小女人 提交于 2019-12-02 04:20:39

get :account (using symbol) and get 'account' (using string) are exactly the same in this context. In your route the symbol will be translated to a string by Rails.

It's just a coding style, I personally use the symbols because I like to see the colors in my IDE, it helps me reading my code faster.

And to answer your other question: no you don't need to define symbols anywhere, those are not a method or a variable. You can see them as a constant with a value equal to their names.

Edit: If it's still confusing you can read this pretty complete guide on symbols in Ruby: http://www.troubleshooters.com/codecorn/ruby/symbols.htm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!