forked from ryanb/railscasts-episodes
/
articles_controller.rb
45 lines (39 loc) · 953 Bytes
/
articles_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id])
@comment = Comment.new(:article_id => @article.id)
end
def new
@article = Article.new
end
def create
@article = Article.new(params[:article])
if @article.save
flash[:notice] = "Successfully created article."
redirect_to @article
else
render :action => 'new'
end
end
def edit
@article = Article.find(params[:id])
end
def update
@article = Article.find(params[:id])
if @article.update_attributes(params[:article])
flash[:notice] = "Successfully updated article."
redirect_to @article
else
render :action => 'edit'
end
end
def destroy
@article = Article.find(params[:id])
@article.destroy
flash[:notice] = "Successfully destroyed article."
redirect_to articles_url
end
end