/
posts_controller.rb
47 lines (37 loc) · 1.05 KB
/
posts_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
46
47
class PostsController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show]
before_filter :load_facebook_client_side_config, :only => [:show]
def index
@posts = Post.order("created_at DESC")
end
def show
@post = Post.find_by_id(params[:id])
@comments = @post.comments.order("created_at DESC")
@comment = @post.comments.build
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
if @post.update_attributes(params[:post])
redirect_to posts_path, :notice => "Your post was edited succesfully"
else
flash[:error] = "There were some errors editing your post"
render action: "edit"
end
end
def new
@post = Post.new
end
def create
@post = Post.new(params[:post])
@post.user = current_user
if @post.save
redirect_to posts_path, :notice => "Your post was created succesfully"
else
flash[:error] = "There were some errors creating your post"
render action: "new"
end
end
end