Class: Blogr::PostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

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



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

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

#editObject



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

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

#indexObject



8
9
10
11
# File 'app/controllers/blogr/posts_controller.rb', line 8

def index
	@posts = Post.order(published_at: :desc)
	@title = "Posts"
end

#newObject



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

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

#showObject



13
14
15
# File 'app/controllers/blogr/posts_controller.rb', line 13

def show
	@title = @post.title
end

#updateObject



38
39
40
41
42
43
44
45
# File 'app/controllers/blogr/posts_controller.rb', line 38

def update

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