Class: Blogr::PostsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/blogr/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



35
36
37
38
39
40
41
42
# File 'app/controllers/blogr/posts_controller.rb', line 35

def create
	@post = current_blogr_user.posts.build(post_params)
	if @post.save
		redirect_to @post, notice: "Post was successfully created"
	else
		render action: "new"
	end
end

#destroyObject



53
54
55
56
# File 'app/controllers/blogr/posts_controller.rb', line 53

def destroy
	@post.destroy
	redirect_to posts_url, notice: "Post was successfully destroyed"
end

#editObject



28
29
30
31
32
33
# File 'app/controllers/blogr/posts_controller.rb', line 28

def edit
	if params[:delete_image]
		Image.find(params[:delete_image]).try :destroy
	end
	@title = "Editing '#{@post.title}'"
end

#indexObject



8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/blogr/posts_controller.rb', line 8

def index
	pub = params[:published] == "false" ? false : true
	@posts = Post.order(published_at: :desc).where(published: pub)
	@title = "Posts"
	if pub
		@subtitle = "Showing Published Posts"
	else
		@subtitle = "Showing Draft Posts"
	end
end

#newObject



23
24
25
26
# File 'app/controllers/blogr/posts_controller.rb', line 23

def new
	@post = Post.new
	@title = "New Post"
end

#showObject



19
20
21
# File 'app/controllers/blogr/posts_controller.rb', line 19

def show
	@title = @post.title
end

#updateObject



44
45
46
47
48
49
50
51
# File 'app/controllers/blogr/posts_controller.rb', line 44

def update

	if @post.update(post_params)
		redirect_to @post, notice: "Post was successfully updated"
	else
		render action: "edit"
	end
end