Permalink
Browse files

[engines guide] Rather than calling name, require a to_s method to be…

… defined on the 'User' class
  • Loading branch information...
1 parent 9694ca1 commit 8ede74e73a45b16a81064a175b3174848469498b @radar radar committed Oct 19, 2011
Showing with 17 additions and 2 deletions.
  1. +17 −2 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
<erb>
<p>
<b>Author:</b>
- <%= @post.author.name %>
+ <%= @post.author %>
</p>
</erb>
-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:
+
+<text>
+#<User:0x00000100ccb3b0>
+</text>
+
+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:
+
+<ruby>
+def to_s
+ name
+</ruby>
+
+Now instead of the ugly Ruby object output the author's name will be displayed.
h4. Configuring an engine

0 comments on commit 8ede74e

Please sign in to comment.