Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
grobie committed Nov 10, 2009
1 parent 73ba406 commit d79000f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 40 deletions.
11 changes: 3 additions & 8 deletions app/controllers/comments_controller.rb
@@ -1,14 +1,9 @@
class CommentsController < ApplicationController

def create
@comment = Comment.new(params[:comment])

if @comment.save
redirect_to @comment.post
else
flash[:notice] = "Bitte alle benötigten Felder ausfüllen!"
render :template => "posts/show", :layout => 'posts'
end
@post = Post.find(params[:post_id])
@comment = @post.comments.create(params[:comment])
redirect_to @post
end

end
2 changes: 2 additions & 0 deletions app/models/post.rb
@@ -1,3 +1,5 @@
class Post < ActiveRecord::Base
has_many :comments

validates_presence_of :title, :body, :author
end
21 changes: 21 additions & 0 deletions app/views/comments/_comments.html.erb
@@ -0,0 +1,21 @@
<h3 id="comments"><%= pluralize @post.comments.size, "Kommentar", "Kommentare" %></h3>

<% for comment in @post.comments %>
<p><strong><%= h comment.author %></strong> kommentierte am <%= comment.created_at.to_s(:short) %></p>
<p><%= simple_format h(comment.content) %></p>
<hr />
<% end %>
<% form_for :comment, :url => post_comments_url(@post) do |f| %>
<p>
<%= f.label :author, "Autor" %><br />
<%= f.text_field :author %>
</p>
<p>
<%= f.label :content, "Kommentar" %><br />
<%= f.text_area :content %>
</p>
<p>
<%= f.submit "abschicken" %>
</p>
<% end %>
6 changes: 3 additions & 3 deletions app/views/posts/index.html.erb
@@ -1,9 +1,9 @@
<% @posts.each do |post| %>
<h2><%= link_to post.title, post %></h2>
<p>
<h2 class="post"><%= link_to post.title, post %></h2>
<span>
geschrieben von <%=h post.author %> am <%= post.created_at.to_s(:short) %>
(<%= link_to pluralize(post.comments.size, "Kommentar", "Kommentare"), post_url(post, :anchor => "comments") %>)
</p>
</span>
<p><%=h post.body %></p>
<% end %>

Expand Down
27 changes: 1 addition & 26 deletions app/views/posts/show.html.erb
Expand Up @@ -5,32 +5,7 @@
<%= simple_format h(@post.body) %>
</p>

<h3 id="comments"><%= pluralize @post.comments.size, "Kommentar", "Kommentare" %></h3>
<% for comment in @post.comments %>
<p><strong><%= h comment.author %></strong> kommentierte am <%= comment.created_at.to_s(:short) %></p>
<p><%= h comment.content %></p>
<hr />
<% end %>
<% form_for :comment, :url => post_comments_url(@post) do |f| %>
<%= f.error_messages %>
<%= f.hidden_field :post_id, :value => @post.id %>

<p>
<%= f.label :author, "Autor" %><br />
<%= f.text_field :author %>
</p>
<p>
<%= f.label :content, "Kommentar" %><br />
<%= f.text_area :content %>
</p>
<p>
<%= f.submit "abschicken" %>
</p>
<% end %>
<%= render :partial => "comments/comments" %>
<%= link_to 'Edit', edit_post_path(@post) %> |
<%= link_to 'Back', posts_path %>
6 changes: 3 additions & 3 deletions public/stylesheets/scaffold.css
@@ -1,4 +1,4 @@
body { background-color: #3366FF; color: #333; }
body { background-color: #4B7399; color: #333; }

div.wrapper {
width: 800px;
Expand Down Expand Up @@ -35,8 +35,8 @@ pre {
font-size: 11px;
}

a { color: #002EB8; text-decoration: underline; }
a:visited { color: #002EB8; }
a { color: #0000FF; text-decoration: underline; }
a:visited { color: #0000FF; }
a:hover { text-decoration: none; }

.fieldWithErrors {
Expand Down

0 comments on commit d79000f

Please sign in to comment.