File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1+ module CommentHelper
2+ end
Original file line number Diff line number Diff line change 1+ class Comment < ActiveRecord ::Base
2+ belongs_to :user
3+ belongs_to :program
4+ end
Original file line number Diff line number Diff line change 11class Program < ActiveRecord ::Base
22 belongs_to :user
3+ has_many :comments
34end
Original file line number Diff line number Diff line change 1+ < h1 > Comment#create</ h1 >
2+ < p > Find me in app/views/comment/create.html.erb</ p >
Original file line number Diff line number Diff line change 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 %>
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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"
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments