Class: Integral::Backend::PostsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/integral/backend/posts_controller.rb

Overview

Post management

Instance Method Summary collapse

Instance Method Details

#activitiesObject

GET /:id/activities



73
74
75
# File 'app/controllers/integral/backend/posts_controller.rb', line 73

def activities
  respond_with_activities(:edit_backend_post_url)
end

#activityObject

GET /:id/activities/:id



78
79
80
81
82
83
84
85
# File 'app/controllers/integral/backend/posts_controller.rb', line 78

def activity
  authorize Version

  add_breadcrumb I18n.t('integral.navigation.activity'), :activities_backend_post_url
  add_breadcrumb I18n.t('integral.actions.view')

  @activity = PostVersion.find(params[:activity_id]).decorate
end

#createObject

POST / Post creation



35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/integral/backend/posts_controller.rb', line 35

def create
  @post = Post.new(post_params)
  @post.user = current_user

  if @post.save
    respond_successfully(notification_message('creation_success'), edit_backend_post_path(@post.id))
  else
    respond_failure(notification_message('creation_failure'), @post, :new)
  end
end

#destroyObject

DELETE /:id



63
64
65
66
67
68
69
70
# File 'app/controllers/integral/backend/posts_controller.rb', line 63

def destroy
  if @post.destroy
    respond_successfully(notification_message('delete_success'), backend_posts_path)
  else
    flash[:error] = notification_message('delete_failure')
    redirect_to backend_posts_path
  end
end

#editObject

GET /:id/edit Post edit form



48
49
50
# File 'app/controllers/integral/backend/posts_controller.rb', line 48

def edit
  add_breadcrumb I18n.t('integral.navigation.edit'), :edit_backend_post_path
end

#indexObject

GET / Lists all posts



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/integral/backend/posts_controller.rb', line 9

def index
  respond_to do |format|
    format.html do
      set_grid(Integral::Grids::PostsGrid)
    end

    format.json do
      if params[:gridview].present?
        set_grid(Integral::Grids::PostsGrid)
        render json: { content: render_to_string(partial: 'integral/backend/posts/grid', locals: { grid: @grid }) }
      else
        respond_to_record_selector(Integral::Post)
      end
    end
  end
end

#newObject

GET /new Post creation form



28
29
30
31
# File 'app/controllers/integral/backend/posts_controller.rb', line 28

def new
  add_breadcrumb I18n.t('integral.navigation.new'), :new_backend_post_path
  @post = Post.new
end

#updateObject

PUT /:id Updating a post



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

def update
  if @post.update(post_params)
    respond_successfully(notification_message('edit_success'), edit_backend_post_path(@post.id))
  else
    respond_failure(notification_message('edit_failure'), @post, :edit)
  end
end