Class: Spina::Admin::Journal::AuthorsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/spina/admin/journal/authors_controller.rb

Overview

Controller for Author records and their corresponding Affiliations.

Instance Method Summary collapse

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 23

def create
  @author = Author.new(modified_params)
  if @author.save
    redirect_to admin_journal_authors_path, success: t('.saved')
  else
    render :new
  end
end

#destroyObject



40
41
42
43
44
45
46
47
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 40

def destroy
  @author.destroy
  respond_to do |format|
    format.html do
      redirect_to admin_journal_authors_path, success: t('.deleted')
    end
  end
end

#editObject



21
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 21

def edit; end

#indexObject



12
13
14
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 12

def index
  @authors = Author.all
end

#newObject



16
17
18
19
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 16

def new
  @author = Author.new
  @author.affiliations << Affiliation.new(status: :primary)
end

#sortObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 49

def sort
  ActiveRecord::Base.transaction do
    sort_params.each do |id, new_pos|
      # ignore uniqueness validation for now
      Authorship.find(id.to_i).update_attribute(:position, new_pos.to_i) # rubocop:disable Rails/SkipsModelValidations
    end
    # do validations after reordering is complete
    validate_sort_order
  end
  render json: { success: true, message: t('.sort_success') }
rescue ActiveRecord::RecordInvalid
  render json: { success: false, message: t('.sort_error') }
end

#updateObject



32
33
34
35
36
37
38
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 32

def update
  if @author.update(modified_params)
    redirect_to admin_journal_authors_path, success: t('.saved')
  else
    render :edit
  end
end