Class: Spina::Admin::Journal::AuthorsController
- Inherits:
-
ApplicationController
- Object
- AdminController
- ApplicationController
- Spina::Admin::Journal::AuthorsController
- Defined in:
- app/controllers/spina/admin/journal/authors_controller.rb
Overview
Controller for Author records and their corresponding Affiliations.
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #sort ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 23 def create = Author.new(modified_params) if .save redirect_to , success: t('.saved') else render :new end end |
#destroy ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 40 def destroy .destroy respond_to do |format| format.html do redirect_to , success: t('.deleted') end end end |
#edit ⇒ Object
21 |
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 21 def edit; end |
#index ⇒ Object
12 13 14 |
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 12 def index = Author.all end |
#new ⇒ Object
16 17 18 19 |
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 16 def new = Author.new .affiliations << Affiliation.new(status: :primary) end |
#sort ⇒ Object
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 |
#update ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/controllers/spina/admin/journal/authors_controller.rb', line 32 def update if .update(modified_params) redirect_to , success: t('.saved') else render :edit end end |