Class: PostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

post /posts



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/posts_controller.rb', line 14

def create
  @entity = Post.new(creation_parameters)
  if @entity.save
    next_page = PostManager.handler(@entity).post_path
    respond_to do |format|
      format.html { redirect_to next_page }
      format.json { render json: { links: { self: next_page } } }
      format.js { render js: "document.location.href = '#{next_page}'" }
    end
  else
    render :new, status: :bad_request
  end
end

#destroyObject

delete /posts/:id



55
56
57
58
59
60
# File 'app/controllers/posts_controller.rb', line 55

def destroy
  if @entity.destroy #@entity.update(deleted: true)
    flash[:notice] = t('posts.destroy.success')
  end
  redirect_to admin_posts_path
end

#editObject

get /posts/:id/edit



37
38
# File 'app/controllers/posts_controller.rb', line 37

def edit
end

#indexObject

get /posts



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

def index
  @collection = Post.page_for_visitors(current_page)
end

#showObject

get /posts/:id



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

def show
  @entity = Post.find_by(id: params[:id], visible: true, deleted: false)
  if @entity.nil?
    handle_http_404("Cannot find non-deleted post #{params[:id]}")
  end
end

#updateObject

patch /posts/:id



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/posts_controller.rb', line 41

def update
  if @entity.update(entity_parameters)
    next_page = PostManager.handler(@entity).post_path
    respond_to do |format|
      format.html { redirect_to next_page }
      format.json { render json: { links: { self: next_page } } }
      format.js { render js: "document.location.href = '#{next_page}'" }
    end
  else
    render :edit, status: :bad_request
  end
end