publication/app/controllers/admin/chapters_controller.rb

60 lines
1.2 KiB
Ruby

class Admin::ChaptersController < OrbitAdminController
def initialize
super
@app_title = "journal"
end
def index
@table_fields = [:title, :author, :page, :sort_number]
@chapters = Chapter.order_by(sort).page(params[:page]).per(10)
render partial: "index" if request.xhr?
end
def new
@chapter = Chapter.new
@journal = Journal.find(params[:journal_id])
if can_edit_or_delete?(@journal)
@tags = @module_app.tags || []
else
render_401
end
end
def create
chapter = Chapter.create(chapter_params)
redirect_to params[:referer_url]
end
def edit
@chapter = Chapter.find(params[:id])
if can_edit_or_delete?(@journal)
@journal = @chapter.journal
else
render_401
end
end
def update
chapter = Chapter.find(params[:id])
chapter.update_attributes(chapter_params)
redirect_to params[:referer_url]
end
def destroy
chapter = Chapter.find(params[:id])
journal = chapter.journal
chapter.destroy
redirect_to admin_journal_path(journal.id, page: params[:page])
end
private
def chapter_params
params.require(:chapter).permit!
end
def setup_vars
@module_app = ModuleApp.where(key: "journal").first
end
end