aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/engines.textile
diff options
context:
space:
mode:
authorRyan Bigg <radarlistener@gmail.com>2011-10-20 08:46:20 +1100
committerRyan Bigg <radarlistener@gmail.com>2011-10-20 08:48:06 +1100
commit8ede74e73a45b16a81064a175b3174848469498b (patch)
tree04d37d92acdfd9e1c75ac93865454453d7aacfe1 /railties/guides/source/engines.textile
parent9694ca1a3bd070886802a6b9f7532adfe5b60cc4 (diff)
downloadrails-8ede74e73a45b16a81064a175b3174848469498b.tar.gz
rails-8ede74e73a45b16a81064a175b3174848469498b.tar.bz2
rails-8ede74e73a45b16a81064a175b3174848469498b.zip
[engines guide] Rather than calling name, require a to_s method to be defined on the 'User' class
Diffstat (limited to 'railties/guides/source/engines.textile')
-rw-r--r--railties/guides/source/engines.textile19
1 files 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
<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