From 8ede74e73a45b16a81064a175b3174848469498b Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Thu, 20 Oct 2011 08:46:20 +1100 Subject: [PATCH] [engines guide] Rather than calling name, require a to_s method to be defined on the 'User' class --- railties/guides/source/engines.textile | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile index 73bbe486e5..02054c972a 100644 --- a/railties/guides/source/engines.textile +++ b/railties/guides/source/engines.textile @@ -476,11 +476,26 @@ Finally, the author's name should be displayed on the post's page. Add this code

Author: - <%= @post.author.name %> + <%= @post.author %>

-NOTE: For posts created previously, this will break the +show+ page for them. We recommend deleting these posts and starting again, or manually assigning an author using +rails c+. +WARNING: For posts created previously, this will break the +show+ page for them. We recommend deleting these posts and starting again, or manually assigning an author using +rails c+. + +By outputting +@post.author+ using the +<%=+ tag the +to_s+ method will be called on the object. By default, this will look quite ugly: + + +# + + +This is undesirable and it would be much better to have the user's name there. To do this, add a +to_s+ method to the +User+ class within the application: + + +def to_s + name + + +Now instead of the ugly Ruby object output the author's name will be displayed. h4. Configuring an engine