From 47ec49276d40ed565d805069bb2a746e9a7b3157 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Wed, 2 May 2012 10:42:59 +0200 Subject: Rewrite comments action in getting started guide --- guides/code/getting_started/app/views/posts/show.html.erb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'guides/code/getting_started') 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 0580879c1a..7066c85065 100644 --- a/guides/code/getting_started/app/views/posts/show.html.erb +++ b/guides/code/getting_started/app/views/posts/show.html.erb @@ -8,6 +8,18 @@ <%= @post.text %>

+

Comments

+<% @post.comments.each do |comment| %> +

+ Commenter: + <%= comment.commenter %> +

+ +

+ Comment: + <%= comment.body %> +

+<% end %>

Add a comment:

<%= form_for([@post, @post.comments.build]) do |f| %> -- cgit v1.2.3 From 323d2c42c3782db9e30b37abb4787fe73d6d7c8d Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Wed, 2 May 2012 11:13:20 +0200 Subject: Rewrite refactoring section in getting started guide --- .../app/views/comments/_comment.html.erb | 8 +++---- .../app/views/comments/_form.html.erb | 12 +++++----- .../getting_started/app/views/posts/show.html.erb | 26 ++-------------------- 3 files changed, 12 insertions(+), 34 deletions(-) (limited to 'guides/code/getting_started') diff --git a/guides/code/getting_started/app/views/comments/_comment.html.erb b/guides/code/getting_started/app/views/comments/_comment.html.erb index 4c3fbf26cd..0cebe0bd96 100644 --- a/guides/code/getting_started/app/views/comments/_comment.html.erb +++ b/guides/code/getting_started/app/views/comments/_comment.html.erb @@ -1,13 +1,13 @@

- Commenter: + Commenter: <%= comment.commenter %>

- +

- Comment: + Comment: <%= comment.body %>

- +

<%= link_to 'Destroy Comment', [comment.post, comment], :confirm => 'Are you sure?', diff --git a/guides/code/getting_started/app/views/comments/_form.html.erb b/guides/code/getting_started/app/views/comments/_form.html.erb index d15bdd6b59..00cb3a08f0 100644 --- a/guides/code/getting_started/app/views/comments/_form.html.erb +++ b/guides/code/getting_started/app/views/comments/_form.html.erb @@ -1,13 +1,13 @@ <%= form_for([@post, @post.comments.build]) do |f| %> -

+

<%= f.label :commenter %>
<%= f.text_field :commenter %> -

-
+

+

<%= f.label :body %>
<%= f.text_area :body %> -

-
+

+

<%= f.submit %> -

+

<% 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 7066c85065..65809033ed 100644 --- a/guides/code/getting_started/app/views/posts/show.html.erb +++ b/guides/code/getting_started/app/views/posts/show.html.erb @@ -9,32 +9,10 @@

Comments

-<% @post.comments.each do |comment| %> -

- Commenter: - <%= comment.commenter %> -

- -

- Comment: - <%= comment.body %> -

-<% end %> +<%= render @post.comments %>

Add a comment:

-<%= form_for([@post, @post.comments.build]) do |f| %> -

- <%= f.label :commenter %>
- <%= f.text_field :commenter %> -

-

- <%= f.label :body %>
- <%= f.text_area :body %> -

-

- <%= f.submit %> -

-<% end %> +<%= render "comments/form" %> <%= link_to 'Edit Post', edit_post_path(@post) %> | <%= link_to 'Back to Posts', posts_path %> -- cgit v1.2.3 From c55ee776232f77a9bd45684a3e6f3f3b13380e4c Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Wed, 2 May 2012 11:39:36 +0200 Subject: Remove tags from getting started guide and adapt some of the content to the new guide --- guides/code/getting_started/app/controllers/comments_controller.rb | 5 +++-- guides/code/getting_started/app/controllers/posts_controller.rb | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'guides/code/getting_started') diff --git a/guides/code/getting_started/app/controllers/comments_controller.rb b/guides/code/getting_started/app/controllers/comments_controller.rb index 7447fd078b..cf3d1be42e 100644 --- a/guides/code/getting_started/app/controllers/comments_controller.rb +++ b/guides/code/getting_started/app/controllers/comments_controller.rb @@ -1,16 +1,17 @@ class CommentsController < ApplicationController http_basic_authenticate_with :name => "dhh", :password => "secret", :only => :destroy + def create @post = Post.find(params[:post_id]) @comment = @post.comments.create(params[:comment]) redirect_to post_path(@post) end - + def destroy @post = Post.find(params[:post_id]) @comment = @post.comments.find(params[:id]) @comment.destroy redirect_to post_path(@post) end - + end diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb index 85d2c1de47..a8ac9aba5a 100644 --- a/guides/code/getting_started/app/controllers/posts_controller.rb +++ b/guides/code/getting_started/app/controllers/posts_controller.rb @@ -1,5 +1,7 @@ class PostsController < ApplicationController + http_basic_authenticate_with :name => "dhh", :password => "secret", :except => [:index, :show] + def index @posts = Post.all end -- cgit v1.2.3