In the Rails docs, it says this:
<%= url_for(@workshop) %>
# calls @workshop.to_s
# => /workshops/5
Is this because the string version of every model in Rails corresponds to a URL for a particular instance of that model?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, the
to_smethod ofObjectprints out the class name. A Rails “model” is usually something that extendsActiveRecord::Base, and looking at the source code for that class shows it does not overrideto_s. My brain is too small to figure out what the source code forurl_foris doing, but I suspect it is not just callingto_son a model but rather doing more work to generate that URL. In Rails, URLs come fromconfig/routes.rbsourl_formust be using that in some way…