aboutsummaryrefslogtreecommitdiffstats
path: root/guides/code/getting_started
diff options
context:
space:
mode:
authorOscar Del Ben <info@oscardelben.com>2012-04-20 12:06:47 +0200
committerOscar Del Ben <info@oscardelben.com>2012-04-20 12:06:47 +0200
commit2e2afc0ac64190261df4b05428afddea96c8628c (patch)
treea94a70200a1ee434d3cfaa82e0040c6166d4692a /guides/code/getting_started
parentdbb4c4ddb601e06fef37f63d644a5297f3292c2a (diff)
downloadrails-2e2afc0ac64190261df4b05428afddea96c8628c.tar.gz
rails-2e2afc0ac64190261df4b05428afddea96c8628c.tar.bz2
rails-2e2afc0ac64190261df4b05428afddea96c8628c.zip
Add show action in getting started guide
Diffstat (limited to 'guides/code/getting_started')
-rw-r--r--guides/code/getting_started/app/controllers/posts_controller.rb7
-rw-r--r--guides/code/getting_started/app/models/post.rb3
-rw-r--r--guides/code/getting_started/app/views/posts/show.html.erb25
-rw-r--r--guides/code/getting_started/config/routes.rb1
4 files changed, 11 insertions, 25 deletions
diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb
index 3373443b16..f9181f98c6 100644
--- a/guides/code/getting_started/app/controllers/posts_controller.rb
+++ b/guides/code/getting_started/app/controllers/posts_controller.rb
@@ -1,5 +1,10 @@
class PostsController < ApplicationController
+
+ def show
+ @post = Post.find(params[:id])
+ end
+
def new
end
@@ -7,6 +12,6 @@ class PostsController < ApplicationController
@post = Post.new(params[:post])
@post.save
- redirect_to :action => :index
+ redirect_to :action => :show, :id => @post.id
end
end
diff --git a/guides/code/getting_started/app/models/post.rb b/guides/code/getting_started/app/models/post.rb
index e77e607f3f..21387340b0 100644
--- a/guides/code/getting_started/app/models/post.rb
+++ b/guides/code/getting_started/app/models/post.rb
@@ -3,7 +3,4 @@ class Post < ActiveRecord::Base
:length => { :minimum => 5 }
has_many :comments, :dependent => :destroy
-
- accepts_nested_attributes_for :tags, :allow_destroy => :true,
- :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
end
diff --git a/guides/code/getting_started/app/views/posts/show.html.erb b/guides/code/getting_started/app/views/posts/show.html.erb
index 3445fd8779..6207babdf0 100644
--- a/guides/code/getting_started/app/views/posts/show.html.erb
+++ b/guides/code/getting_started/app/views/posts/show.html.erb
@@ -1,26 +1,9 @@
-<p class="notice"><%= notice %></p>
-
<p>
- <b>Name:</b>
- <%= @post.name %>
-</p>
-
-<p>
- <b>Title:</b>
+ <strong>Title:</strong>
<%= @post.title %>
</p>
-
+
<p>
- <b>Content:</b>
- <%= @post.content %>
+ <strong>Text:</strong>
+ <%= @post.text %>
</p>
-
-<h2>Comments</h2>
-<%= render @post.comments %>
-
-<h2>Add a comment:</h2>
-<%= render "comments/form" %>
-
-
-<%= link_to 'Edit Post', edit_post_path(@post) %> |
-<%= link_to 'Back to Posts', posts_path %> |
diff --git a/guides/code/getting_started/config/routes.rb b/guides/code/getting_started/config/routes.rb
index 98b1a6dcc8..7210b559bb 100644
--- a/guides/code/getting_started/config/routes.rb
+++ b/guides/code/getting_started/config/routes.rb
@@ -5,6 +5,7 @@ Blog::Application.routes.draw do
get "posts/new"
post "posts/create"
+ get "posts/:id" => "posts#show"
# The priority is based upon order of creation:
# first created -> highest priority.