Skip to content

Commit 86f80f5

Browse files
committed
comments work
1 parent d75a032 commit 86f80f5

14 files changed

Lines changed: 420 additions & 3 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class CommentsController < ApplicationController
2+
def create
3+
@comment = Comment.new(params[:comment])
4+
@comment.user = current_user
5+
6+
if @comment.save
7+
flash[:notice] = 'Comment was successfully created.'
8+
redirect_to(@comment.program)
9+
else
10+
render :action => "new"
11+
end
12+
end
13+
14+
end

app/helpers/comment_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module CommentHelper
2+
end

app/models/comment.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Comment < ActiveRecord::Base
2+
belongs_to :user
3+
belongs_to :program
4+
end

app/models/program.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class Program < ActiveRecord::Base
22
belongs_to :user
3+
has_many :comments
34
end

app/views/comment/create.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>Comment#create</h1>
2+
<p>Find me in app/views/comment/create.html.erb</p>

app/views/programs/show.html.erb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,16 @@
2020

2121

2222
<%= link_to 'Edit', edit_program_path(@program) %> |
23-
<%= link_to 'Back', programs_path %>
23+
<%= link_to 'Back', programs_path %>
24+
25+
<h2>Make a comment</h2>
26+
<% form_for Comment.new do |f| %>
27+
<%= f.text_area :text %><br />
28+
<%= f.hidden_field :program_id, :value => @program.id %>
29+
<%= f.submit %>
30+
<% end %>
31+
32+
<h2>Previous comments</h2>
33+
<% @program.comments.reverse.each do |comment| %>
34+
<p><%= comment.user.username %>: <%= comment.text %></p>
35+
<% end %>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
map.resources :user_sessions
1818
map.resources :watchings
19+
map.resources :comments
1920

2021
map.inbox "/dashboard/inbox", :controller => "dashboard", :action => "inbox"
2122

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class CreateComments < ActiveRecord::Migration
2+
def self.up
3+
create_table :comments do |t|
4+
t.integer :user_id
5+
t.text :text
6+
t.integer :program_id
7+
8+
t.timestamps
9+
end
10+
end
11+
12+
def self.down
13+
drop_table :comments
14+
end
15+
end

db/schema.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
#
1010
# It's strongly recommended to check this file into your version control system.
1111

12-
ActiveRecord::Schema.define(:version => 20091219054931) do
12+
ActiveRecord::Schema.define(:version => 20091219060017) do
13+
14+
create_table "comments", :force => true do |t|
15+
t.integer "user_id"
16+
t.text "text"
17+
t.integer "program_id"
18+
t.datetime "created_at"
19+
t.datetime "updated_at"
20+
end
1321

1422
create_table "messages", :force => true do |t|
1523
t.integer "sender_id"

generate

Lines changed: 328 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)