Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
33 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Post < ActiveRecord::Base | ||
has_many :comments | ||
|
||
validates_presence_of :title, :body, :author | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters