Class: Blog::Gem::PostsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_author, #login_as_author

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/blog/gem/posts_controller.rb', line 17

def create
  @post = Blog::Gem::Post.new(post_params)

  if !current_author.admin?
    @post.author_id = current_author.id
  end

  respond_to do |format|
    if @post.save
      format.html { redirect_to @post.to_path, notice: 'Post was successfully created.' }
    else
      format.html { render :new }
    end
  end
end

#destroyObject



46
47
48
49
50
51
# File 'app/controllers/blog/gem/posts_controller.rb', line 46

def destroy
  @post.destroy
  respond_to do |format|
    format.html { redirect_to blogs_url, notice: 'Post was successfully destroyed.' }
  end
end

#editObject



14
15
# File 'app/controllers/blog/gem/posts_controller.rb', line 14

def edit
end

#newObject



9
10
11
12
# File 'app/controllers/blog/gem/posts_controller.rb', line 9

def new
  @post = Blog::Gem::Post.new(author_id: current_author.id, show_author: true)
  @page_title = "New Blog Post"
end

#updateObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/blog/gem/posts_controller.rb', line 33

def update
  if !current_author.admin?
    post_params[:author_id] = current_author.id
  end
  respond_to do |format|
    if @post.update(post_params)
      format.html { redirect_to @post.to_path, notice: 'Post was successfully updated.' }
    else
      format.html { render :edit }
    end
  end
end