-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
58a654b
commit cf20a96
Showing
14 changed files
with
282 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
class CommentsController < ApplicationController | ||
# GET /comments | ||
# GET /comments.xml | ||
def index | ||
@comments = Comment.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.xml { render :xml => @comments } | ||
end | ||
end | ||
|
||
# GET /comments/1 | ||
# GET /comments/1.xml | ||
def show | ||
@comment = Comment.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.xml { render :xml => @comment } | ||
end | ||
end | ||
|
||
# GET /comments/new | ||
# GET /comments/new.xml | ||
def new | ||
@comment = Comment.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @comment } | ||
end | ||
end | ||
|
||
# GET /comments/1/edit | ||
def edit | ||
@comment = Comment.find(params[:id]) | ||
end | ||
|
||
# POST /comments | ||
# POST /comments.xml | ||
def create | ||
@comment = Comment.new(params[:comment]) | ||
|
||
respond_to do |format| | ||
if @comment.save | ||
flash[:notice] = 'Comment was successfully created.' | ||
format.html { redirect_to(@comment) } | ||
format.xml { render :xml => @comment, :status => :created, :location => @comment } | ||
else | ||
format.html { render :action => "new" } | ||
format.xml { render :xml => @comment.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /comments/1 | ||
# PUT /comments/1.xml | ||
def update | ||
@comment = Comment.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @comment.update_attributes(params[:comment]) | ||
flash[:notice] = 'Comment was successfully updated.' | ||
format.html { redirect_to(@comment) } | ||
format.xml { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.xml { render :xml => @comment.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /comments/1 | ||
# DELETE /comments/1.xml | ||
def destroy | ||
@comment = Comment.find(params[:id]) | ||
@comment.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to(comments_url) } | ||
format.xml { head :ok } | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CommentsHelper | ||
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,2 @@ | ||
class Comment < ActiveRecord::Base | ||
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,24 @@ | ||
<h1>Editing comment</h1> | ||
|
||
<% form_for(@comment) do |f| %> | ||
<%= f.error_messages %> | ||
|
||
<p> | ||
<%= f.label :content %><br /> | ||
<%= f.text_area :content %> | ||
</p> | ||
<p> | ||
<%= f.label :link_id %><br /> | ||
<%= f.text_field :link_id %> | ||
</p> | ||
<p> | ||
<%= f.label :user_id %><br /> | ||
<%= f.text_field :user_id %> | ||
</p> | ||
<p> | ||
<%= f.submit 'Update' %> | ||
</p> | ||
<% end %> | ||
|
||
<%= link_to 'Show', @comment %> | | ||
<%= link_to 'Back', comments_path %> |
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,24 @@ | ||
<h1>Listing comments</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Content</th> | ||
<th>Link</th> | ||
<th>User</th> | ||
</tr> | ||
|
||
<% @comments.each do |comment| %> | ||
<tr> | ||
<td><%=h comment.content %></td> | ||
<td><%=h comment.link_id %></td> | ||
<td><%=h comment.user_id %></td> | ||
<td><%= link_to 'Show', comment %></td> | ||
<td><%= link_to 'Edit', edit_comment_path(comment) %></td> | ||
<td><%= link_to 'Destroy', comment, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New comment', new_comment_path %> |
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,23 @@ | ||
<h1>New comment</h1> | ||
|
||
<% form_for(@comment) do |f| %> | ||
<%= f.error_messages %> | ||
|
||
<p> | ||
<%= f.label :content %><br /> | ||
<%= f.text_area :content %> | ||
</p> | ||
<p> | ||
<%= f.label :link_id %><br /> | ||
<%= f.text_field :link_id %> | ||
</p> | ||
<p> | ||
<%= f.label :user_id %><br /> | ||
<%= f.text_field :user_id %> | ||
</p> | ||
<p> | ||
<%= f.submit 'Create' %> | ||
</p> | ||
<% end %> | ||
|
||
<%= link_to 'Back', comments_path %> |
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,18 @@ | ||
<p> | ||
<b>Content:</b> | ||
<%=h @comment.content %> | ||
</p> | ||
|
||
<p> | ||
<b>Link:</b> | ||
<%=h @comment.link_id %> | ||
</p> | ||
|
||
<p> | ||
<b>User:</b> | ||
<%=h @comment.user_id %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_comment_path(@comment) %> | | ||
<%= link_to 'Back', comments_path %> |
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,17 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | ||
<title>Comments: <%= controller.action_name %></title> | ||
<%= stylesheet_link_tag 'scaffold' %> | ||
</head> | ||
<body> | ||
|
||
<p style="color: green"><%= flash[:notice] %></p> | ||
|
||
<%= yield %> | ||
|
||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateComments < ActiveRecord::Migration | ||
def self.up | ||
create_table :comments do |t| | ||
t.text :content | ||
t.integer :link_id | ||
t.integer :user_id | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :comments | ||
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
||
one: | ||
content: MyText | ||
link_id: 1 | ||
user_id: 1 | ||
|
||
two: | ||
content: MyText | ||
link_id: 1 | ||
user_id: 1 |
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,45 @@ | ||
require 'test_helper' | ||
|
||
class CommentsControllerTest < ActionController::TestCase | ||
test "should get index" do | ||
get :index | ||
assert_response :success | ||
assert_not_nil assigns(:comments) | ||
end | ||
|
||
test "should get new" do | ||
get :new | ||
assert_response :success | ||
end | ||
|
||
test "should create comment" do | ||
assert_difference('Comment.count') do | ||
post :create, :comment => { } | ||
end | ||
|
||
assert_redirected_to comment_path(assigns(:comment)) | ||
end | ||
|
||
test "should show comment" do | ||
get :show, :id => comments(:one).to_param | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get :edit, :id => comments(:one).to_param | ||
assert_response :success | ||
end | ||
|
||
test "should update comment" do | ||
put :update, :id => comments(:one).to_param, :comment => { } | ||
assert_redirected_to comment_path(assigns(:comment)) | ||
end | ||
|
||
test "should destroy comment" do | ||
assert_difference('Comment.count', -1) do | ||
delete :destroy, :id => comments(:one).to_param | ||
end | ||
|
||
assert_redirected_to comments_path | ||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'test_helper' | ||
|
||
class CommentTest < ActiveSupport::TestCase | ||
# Replace this with your real tests. | ||
test "the truth" do | ||
assert true | ||
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class CommentsHelperTest < ActionView::TestCase | ||
end |