Class: Pulitzer::VersionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pulitzer/versions_controller.rb

Instance Method Summary collapse

Instance Method Details

#editObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/pulitzer/versions_controller.rb', line 4

def edit
  if @version.preview?
    route = "#{Pulitzer.preview_namespace}_#{@post.post_type.name.parameterize('_')}_path"
    if main_app.respond_to?(route)
      if @post.plural?
        @preview_path = main_app.public_send(route, @post.slug, {version_number: @post.post_type_version.version_number})
      else
        @preview_path = main_app.public_send(route, {version_number: @post.post_type_version.version_number})
      end
    end
  end
  render_ajax locals: { version: @version }
end

#updateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/pulitzer/versions_controller.rb', line 18

def update
  status_updater = Pulitzer::UpdateVersionStatus.new(@version, @status)
  if status_updater.errors.any?
    processing_version  = @version
    flash_message       = status_updater.errors.join("<br>").html_safe
    status = :conflict
  else
    processing_version  = status_updater.call
    if processing_version
      if processing_version.errors.empty?
        status = :ok
        flash_message     = "The new version of #{@post.title} has been activated."
      else
        status = :conflict
        flash_message = processing_version.errors.full_messages.join("<br>").html_safe
      end
    else
      flash[:notice] = "The post was successfully removed."
      render json: {class_triggers: {"hooch.ReloadPage" => posts_path(post_type_id: @version.post.post_type.id) }} and return
    end
  end
  render json: {html: render_to_string(partial: '/pulitzer/versions/edit', locals: {version: processing_version}),
                flash_message: flash_message}, status: status
end